-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp-server.js
More file actions
33 lines (27 loc) · 911 Bytes
/
Copy pathhttp-server.js
File metadata and controls
33 lines (27 loc) · 911 Bytes
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
31
32
33
const express = require('express');
const {createProxyMiddleware} = require('http-proxy-middleware');
const open = require('open');
const cliParams = process.argv.slice(2);
const rewritePaths = cliParams.includes('--rewrite-paths');
const port = 8899;
const app = express();
const ROUTER = {
'/react': 'http://localhost:3000',
'/vue': 'http://localhost:8081',
'/svelte': 'http://localhost:8181',
};
const proxyMiddleware = createProxyMiddleware({
target: 'http://please-ignore-this-hostname', // must be set even when router is used
router: ROUTER,
changeOrigin: true,
pathRewrite: rewritePaths ? {
'^/apps/[^\\/]+': ''
} : undefined
});
app.use('/apps', proxyMiddleware);
app.use(express.static(__dirname));
app.listen(port, () => {
const url = `http://localhost:${port}`;
console.log(`HTTP server is running on ${url}`);
open(`${url}/index.html`);
});