proxy error fix

This commit is contained in:
Ben Allfree 2022-12-24 14:45:19 +00:00
parent b77e9cdb3a
commit 338c4bc32b

View File

@ -9,6 +9,9 @@ const options = {
}
const proxy = httpProxy.createProxyServer({})
proxy.on('error', (e) => {
console.error(e)
})
const server = createServer(options, async (req, res) => {
const headers = {
@ -26,10 +29,17 @@ const server = createServer(options, async (req, res) => {
console.log(req.headers.host)
const { host } = req.headers
if (host === process.env.PUBLIC_APP_DOMAIN) {
proxy.web(req, res, { target: `http://localhost:5173` })
} else {
proxy.web(req, res, { target: `http://localhost:3000` })
try {
if (host === process.env.PUBLIC_APP_DOMAIN) {
proxy.web(req, res, { target: `http://localhost:5173` })
} else {
proxy.web(req, res, { target: `http://localhost:3000` })
}
} catch (e) {
console.error(`Got an error ${e}`)
res.statusCode = 500
res.end()
}
})