cryptgeon/proxy.mjs

20 lines
448 B
JavaScript
Raw Normal View History

2021-12-20 18:14:59 +01:00
import http from 'http'
2021-12-22 13:10:08 +01:00
import httpProxy from 'http-proxy'
2021-12-20 18:14:59 +01:00
2021-12-22 14:46:06 +01:00
function start() {
try {
const proxy = httpProxy.createProxyServer({})
const server = http.createServer(function (req, res) {
const target = req.url.startsWith('/api/') ? 'http://localhost:5000' : 'http://localhost:3000'
proxy.web(req, res, { target })
})
server.listen(1234)
2021-12-20 18:14:59 +01:00
2021-12-22 14:46:06 +01:00
server.on('error', () => start())
} catch (e) {
start()
}
}
2021-12-20 18:14:59 +01:00
2021-12-22 14:46:06 +01:00
start()