简体   繁体   English

node.js angular.js 从配置中获取端口

[英]node.js angular.js get port from config

In my root directory, I have a config.json file that contains the port that the web server should listen to.在我的根目录中,我有一个 config.json 文件,其中包含 Web 服务器应该侦听的端口。 This makes it easier for anyone using the app, but I can't GET/POST without knowing the port.这使使用该应用程序的任何人都更容易,但我无法在不知道端口的情况下进行 GET/POST。

I can't access the config.json file as it's in my root directory while the AngularJS controllers are in a deeper directory.我无法访问 config.json 文件,因为它位于我的根目录中,而 AngularJS 控制器位于更深的目录中。

If your Angular app makes relative calls, it shouldn't need to be specified.如果您的 Angular 应用程序进行相对调用,则不需要指定它。 If you can't make all relative calls, then create a route that supplies Angular config, and call that relatively.如果您不能进行所有相关调用,则创建一个提供 Angular 配置的路由,并进行相对调用。

使用相对 URL 或var full = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM