You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
app.use('/proxy',proxy({logLevel: 'info',target: 'http://localhost',router: function(req){// SAMPLE REQUEST: /proxy?url=http%3A%2F%2Flocalhost%3A7000%2Fapi-docs%3Ffoo%3D1%26bar%3D42consturl=req.query.url// console.log('URL: ', url)consturlModule=require('url')consturlObject=urlModule.parse(url)// console.log(urlObject)consttarget=`${urlObject.protocol}//${urlObject.host}`// console.log('TARGET:', target)returntarget},pathRewrite: function(path,req){// console.log()// SAMPLE REQUEST: /proxy?url=http%3A%2F%2Flocalhost%3A7000%2Fapi-docs%3Ffoo%3D1%26bar%3D42// SAMPLE REQUEST (url decoded): http://localhost:3002/proxy?url=http://localhost:7000/api-docs// console.log('REWRITE URL: ', req.query.url)consturlModule=require('url')consturlObject=urlModule.parse(req.query.url)// console.log('REWRITE PATH', urlObject.path)returnurlObject.path},changeOrigin: true,onError: onProxyError}))functiononProxyError(err,req,res){varhost=req.headers&&req.headers.hostconsole.log(chalk.red('Proxy error:')+' Could not proxy request '+chalk.cyan(req.url))console.log()// And immediately send the proper error response to the client.// Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.if(res.writeHead&&!res.headersSent){res.writeHead(500);}res.end('Proxy error: Could not proxy request '+req.url+'.')}
The text was updated successfully, but these errors were encountered:
The existing samples of API Explorer server uses a buggy implementation for proxy the requests.
I propose to use https://github.com/chimurai/http-proxy-middleware to proxy request to the target server.
Sample implementation:
The text was updated successfully, but these errors were encountered: