[英]Forward all requests in in Node.js/Koa server from http://server/api/* to another ip?
I'm using Node.js and Koa to build a web server. 我正在使用Node.js和Koa来构建Web服务器。 However, I'd like to merge it with another server located at 192.168.1.5:80. 但是,我想将其与位于192.168.1.5:80的另一台服务器合并。 How can I make it so that all requests to {my web server}:80/api/* are exactly the same as requests to 192.168.1.5:80/api/*. 如何使所有对{我的Web服务器}:80 / api / *的请求与对192.168.1.5:80/api/*的请求完全相同。
Thanks in advance! 提前致谢!
You could use koa-proxy: 您可以使用koa-proxy:
https://www.npmjs.com/package/koa-proxy https://www.npmjs.com/package/koa-proxy
Then for the proxy, your code could look like this: 然后对于代理,您的代码可能如下所示:
var koa = require('koa');
var proxy = require('koa-proxy');
var app = koa();
app.use(proxy({
host: 'http://192.168.1.5', // proxy to 192.168.1.5:80...
match: /^\/api\// // ...just the /api routes
}));
app.listen(80);
hope that helps ... (not testet) 希望有帮助...(不是睾丸)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.