cryptgeon/proxy.mjs

16 lines
502 B
JavaScript
Raw Normal View History

2021-12-20 17:14:59 +00:00
import http from 'http'
2021-12-22 12:10:08 +00:00
import httpProxy from 'http-proxy'
2021-12-20 17:14:59 +00:00
2022-01-03 17:16:54 +00:00
const proxy = httpProxy.createProxyServer()
proxy.on('error', function (err, req, res) {
res.writeHead(500, { 'Content-Type': 'text/plain' })
res.end('500 Internal Server Error')
})
2021-12-20 17:14:59 +00:00
2022-01-03 17:16:54 +00:00
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)
console.log('Proxy on http://localhost:1234')