Skip to content

Instantly share code, notes, and snippets.

@smashercosmo
Created February 28, 2019 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smashercosmo/6f9d1b3992fe41ca0bea834d850f1e9b to your computer and use it in GitHub Desktop.
Save smashercosmo/6f9d1b3992fe41ca0bea834d850f1e9b to your computer and use it in GitHub Desktop.
proxy
const api = route.all('/api/(.*)', async (ctx, next) => {
ctx.respond = false
const { res, req, url, method, headers } = ctx
const proxyUrl = new URL(
BASE_URL + url.replace(/^\/api/, '/api/v2'),
)
const proxyReq = makeProxyRequest({
url: proxyUrl,
method,
headers,
})
req.pipe(proxyReq)
proxyReq.on('response', async proxyRes => {
res.writeHead(finalResponse.statusCode, finalResponse.headers)
proxyRes.pipe(res)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment