-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-proxy.js
30 lines (24 loc) · 1.26 KB
/
server-proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const path = require('path');
const express = require('express');
const webpack = require('webpack');
const historyFallback = require('connect-history-api-fallback');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const proxyMiddleware = require('http-proxy-middleware');
const WebpackConfig = require('./webpack.config');
const port = process.env.PORT || 3000;
const apiProxy = {
target: process.env.API_PROXY || 'http://results-manager.dev.onshape.com', // Must be in the onshape VPN network to access this page
changeOrigin: true,
logLevel: 'debug' // for less verbose output, try 'warn'
}
const app = express();
const compiler = webpack(WebpackConfig);
app.use(historyFallback()); // convert localhost:3000/url/path to localhost:3000/#/url/path if the request fails
app.use(webpackDevMiddleware(compiler, WebpackConfig.devServer));
app.use(webpackHotMiddleware(compiler));
app.use('/static', express.static('static')); // serve assets to the /static directory on the server
app.use(proxyMiddleware('/data', apiProxy)); // route all calls to /data to the remote backend
module.exports = app.listen(port, () => {
console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`);
});