我希望我正确理解了您的问题,您实际上可以发出代理请求并将其响应传递给您的应用响应。
var http = require("http");
var express = require("express");
var app = express();
var options = {
host: "stackoverflow.com",
port: 80,
path: "/",
method: "GET",
headers: {}
};
app.get("/stackoverflow*", function (request, response) {
"use strict";
var proxyRequest;
options.headers.cookie = request.headers.cookie;
options.headers["user-agent"] = request.headers["user-agent"];
// TODO set other headers if needed
options.path = "/" + request.path.split("/").slice(2).join("/");
options.method = request.method;
proxyRequest = http.request(options, function (proxyResponse) {
proxyResponse.pipe(response);
});
request.pipe(proxyRequest);
}).listen(8080);
现在您可以导航到http://localhost:8080/stackoverflow/questions/14880557/how-to-connect-appjs-to-nodejs-server-and-show-its-content/14890268#14890268
并且您的应用程序将显示来自 的请求路径stackoverflow.com
。