Last active
May 30, 2024 10:00
-
-
Save peterreisz/96593915c407de2d139120ade96c9be0 to your computer and use it in GitHub Desktop.
Dev server proxy for stencil. Backend is running on port 3000, stencil on 3333, open port 5000 for development. Only `/api` requests are sent to the backend, everything else served by stencil.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const httpProxy = require('http-proxy'); | |
const proxyApi = new httpProxy.createProxyServer({ | |
target: { | |
host: '127.0.0.1', | |
port: 3000 | |
} | |
}); | |
proxyApi.on('error', () => {}); | |
const proxyStencil = new httpProxy.createProxyServer({ | |
target: { | |
host: '127.0.0.1', | |
port: 3333 | |
} | |
}); | |
proxyStencil.on('error', () => {}); | |
const proxyServer = http.createServer((req, res) => { | |
if (req.url.match(/\/api/)) { | |
proxyApi.web(req, res); | |
} else { | |
proxyStencil.web(req, res); | |
} | |
}); | |
proxyServer.on('error', () => {}); | |
proxyServer.on('upgrade', (req, socket, head) => { | |
proxyStencil.ws(req, socket, head); | |
}); | |
console.log('Listen: http://127.0.0.1:5000'); | |
proxyServer.listen(5000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "stencil-dev-proxy", | |
"version": "0.1.0", | |
"main": "index.js", | |
"scripts": { | |
"start": "node index.js" | |
}, | |
"license": "MIT", | |
"devDependencies": { | |
"http-proxy": "^1.17.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment