Node.js 将http请求从客户端发送到heroku平台内的服务器

Node.js 将http请求从客户端发送到heroku平台内的服务器,node.js,angular,web,heroku,Node.js,Angular,Web,Heroku,我的应用程序在客户端使用angular,在后台使用nodejs,但在heroku上的生产环境中正确配置它们时,我遇到了一些问题 在开发过程中,我在端口3000上运行我的nodejs服务器,并将所有http请求从angular客户端发送到http://localhost:3000,它的工作原理非常好。 但是,当我在dist目录下部署nodejs服务器和angular客户端文件时,heroku将服务器提升到随机端口,并将所有http请求提升到http://localhost:3000失败。如何确定h

我的应用程序在客户端使用angular,在后台使用nodejs,但在heroku上的生产环境中正确配置它们时,我遇到了一些问题

在开发过程中,我在端口3000上运行我的nodejs服务器,并将所有http请求从angular客户端发送到
http://localhost:3000
,它的工作原理非常好。 但是,当我在dist目录下部署nodejs服务器和angular客户端文件时,heroku将服务器提升到随机端口,并将所有http请求提升到
http://localhost:3000
失败。如何确定heroku上的节点端口,或者如何在angular客户端中获取节点端口

服务器上的代码:

let port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log('app listening on port ' 
+ port));
server.on('error', onError);
server.on('listening', onListening);
客户机上的代码:

export const environment = {
  production: true,
  serverUrl: 'http://localhost:3000'
};

我认为您可以直接使用Heroku提供的后端URL。这里不需要任何端口。因为它将使用端口80作为默认端口<代码>例如:https://example.herokuapp.com/

是的,这是可能的,但我认为向localhost+端口发送请求比向域名发送http请求快得多。也许我错了,就我所知,你的方式被认为是最好的做法。在Heroku,没有办法知道应用程序部署在哪个IP和端口上。最好使用域名。云提供商足够聪明,可以快速解析DNS。