-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (27 loc) · 836 Bytes
/
server.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
31
32
33
// Based on https://github.com/http-party/node-http-proxy#proxying-websockets
import http from 'http';
import httpProxy from 'http-proxy';
//
// Setup our server to proxy standard HTTP requests
//
const proxy = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 8080,
},
});
proxy.on('proxyRes', (proxyRes, req, res) => {
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
})
const proxyServer = http.createServer((req, res) => {
proxy.web(req, res);
});
//
// Listen to the `upgrade` event and proxy the
// WebSocket requests as well.
//
proxyServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head);
});
proxyServer.listen(8081, () => console.log('Listening on port 8081'));