cryptgeon/packages/proxy/proxy.js

17 lines
556 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) {
2023-01-04 18:40:37 +00:00
console.error(err)
2022-01-03 17:16:54 +00:00
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) {
2023-01-13 18:36:26 +00:00
const target = req.url.startsWith('/api/') ? 'http://127.0.0.1:8000' : 'http://localhost:8001'
2023-05-23 07:37:33 +00:00
proxy.web(req, res, { target, proxyTimeout: 250, timeout: 250 })
2022-01-03 17:16:54 +00:00
})
2024-08-23 12:27:17 +00:00
server.listen(3000)
console.log('Proxy on http://localhost:3000')