mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-22 16:26:28 +00:00
17 lines
556 B
JavaScript
17 lines
556 B
JavaScript
import http from 'http'
|
|
import httpProxy from 'http-proxy'
|
|
|
|
const proxy = httpProxy.createProxyServer()
|
|
proxy.on('error', function (err, req, res) {
|
|
console.error(err)
|
|
res.writeHead(500, { 'Content-Type': 'text/plain' })
|
|
res.end('500 Internal Server Error')
|
|
})
|
|
|
|
const server = http.createServer(function (req, res) {
|
|
const target = req.url.startsWith('/api/') ? 'http://127.0.0.1:8000' : 'http://localhost:8001'
|
|
proxy.web(req, res, { target, proxyTimeout: 250, timeout: 250 })
|
|
})
|
|
server.listen(3000)
|
|
console.log('Proxy on http://localhost:3000')
|