【发布时间】:2019-08-16 01:57:47
【问题描述】:
我希望使用我的公共 IP 地址而不是本地主机来访问我的 Nodejs 应用程序。现在为了在本地主机上托管我的应用程序,我正在做:
app.listen(process.env.PORT||9000,()=>{
console.log('Server is running on 9000!')
})
我想设置 Nodejs 到 Nodejs 的通信。我从stackoverflow和
使用 npm request 包从运行在端口 3000 上的一台 nodejs 服务器向运行在端口 9000 上的一台服务器发送发布请求
const request = require("request");
var options = {
method: 'POST',
url: 'http://localhost:9000/',
headers: { 'Content-Type': 'application/json' },
body: { id: 1 },
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
// console.log(body);
// Process the body and return the response.
// return res.send(body);
});
但是,我想使用公共 IP 地址,因为我想在 Heroku 上托管我的一台服务器。我将需要公共 IP 地址来创建通信
【问题讨论】:
-
到目前为止,您在部署应用程序方面做了哪些尝试?您是否有服务器设置和访问权限?是否要将应用程序 docker 化?