Node.js 在同一节点进程中的2个express应用之间路由
在我使用express的应用程序中,我有一个第三方node.js应用程序,它使用http而不是express,并通过这样做来处理它的路由(抖动) 现在,在我的应用程序中,我想截取其中一条路由(/foo),但它似乎不起作用,因为removeAllListeners()会将其破坏 如果我删除removeAllListeners(),那么我的app.get('/foo',(){})会启动,但是srv.on('request')也会启动,从而导致各种严重错误 我想我可以通过创建两个http服务器来解决这个问题——一个用于我的应用程序,另一个用于第三方应用程序,并将第三方应用程序配置为在专用端口上侦听。计划是将所有“拦截”钩子放入我的应用程序中,如果没有匹配项,则将请求传递给第三方http服务器 我宁愿不必启动两个节点进程来处理这个问题 因此,对于问题: 是否可以将请求从一个节点http服务器路由到另一个节点http服务器,而不向客户端发出重定向Node.js 在同一节点进程中的2个express应用之间路由,node.js,express,Node.js,Express,在我使用express的应用程序中,我有一个第三方node.js应用程序,它使用http而不是express,并通过这样做来处理它的路由(抖动) 现在,在我的应用程序中,我想截取其中一条路由(/foo),但它似乎不起作用,因为removeAllListeners()会将其破坏 如果我删除removeAllListeners(),那么我的app.get('/foo',(){})会启动,但是srv.on('request')也会启动,从而导致各种严重错误 我想我可以通过创建两个http服务器来解决这
var express = require('express'),
myApp = express(),
myServer = http.createServer(myApp),
tpServer = require('thirdparty')({port:1234}); // returns a node httpServer
myApp.get('/foo ...
myApp.get('/bar ...
myApp.get('*', (req,res,next) => {
/* do something here to pass request to tpServer */
})
谢谢
var express = require('express'),
myApp = express(),
myServer = http.createServer(myApp),
tpServer = require('thirdparty')({port:1234}); // returns a node httpServer
myApp.get('/foo ...
myApp.get('/bar ...
myApp.get('*', (req,res,next) => {
/* do something here to pass request to tpServer */
})