[英]How can I provide a client application (port 443) the ability to consume a REST API (port 9000) on the same server when the port is not public facing?
我正在用express和ui-router在節點上運行一個有角度的(1.5+)應用程序,我想將此應用程序連接到在同一服務器上運行但在未面向公眾的端口(9000)上運行的REST API。 。
如何使用服務器端邏輯配置我的角度應用程序和快速服務器以使用端口9000上的REST API?
我想在端口9000上訪問REST API的示例路由和參數為https://example.com/item/123
通常我使用Express Http Proxy來解決此問題。 這是非常可配置的。
示例代碼為:
var proxy = require('express-http-proxy');
// app is your express based Web application in port 443
var app = require('express')();
app.use('/item', proxy('localhost:9000', {
forwardPath: function(req, res) {
return require('url').parse(req.url).path;
}
}));
使用此中間件,您可以在對私有API的請求執行之前和之后提供對請求的自定義處理。 閱讀文檔以獲取更多示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.