Created
February 28, 2019 11:58
-
-
Save smashercosmo/6f9d1b3992fe41ca0bea834d850f1e9b to your computer and use it in GitHub Desktop.
proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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