[英]Dynamically connect to NodeJS server using socket.io
I have an ionic chatting app and a nodejs server , it works fine , the only issue that is the server ip/port is hardcoded in a config object. 我有一个离子聊天应用程序和一个nodejs服务器,它工作正常,唯一的问题是服务器ip / port硬编码在config对象中。
let config = { url:"192.168.1.4:3000" , opt: ""}
But I would like to change this approach, and fetch the server ip/port dynamically or from a file ? 但是我想更改这种方法,并动态地或从文件中获取服务器的ip / port?
You can create a config.js file and put your things there 您可以创建一个config.js文件并将其放到那里
Config.js: Config.js:
{
url:"192.168.1.4:3000"
}
And import the file: 并导入文件:
var cnfg = require('./config');
let config = { url:cnfg.url , opt: ""}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.