pomelo-cn icon indicating copy to clipboard operation
pomelo-cn copied to clipboard

三条建议

Open ETiV opened this issue 13 years ago • 6 comments

  1. Pomelo模板下, servers.json 配置文件中的host, 推荐改成0.0.0.0, 而不是现在的127.0.0.1. 多数有经验的程序员/系统管理员, 看到这个配置, 会以为程序只驻守127.0.0.1网络地址. 而修改后, 更符合思维惯性. (同时starter.js里的isLocal也应一并修改.)
  2. game-server/app.js中, 除非大部分client库都已支持Pomelo 0.3版本的新协议, 否则不推荐默认代码中直接使用hybirdconnector和数据压缩配置. 而应在app.jsentryHandler.js中加以注释, 告知用户可以切换到hybirdconnector的条件.
  3. 感觉用json文件作为配置文件有一点不好, 没法插入评论. 导致很多才接触Pomelo的人对着初始化新项目后的配置文件手足无措. 比如第一条建议中出现的情况. 更多的发生在带有gate服务器, 用来负载均衡的时候. 人们不知道怎么设置. 而如果此时在"connector"后面加入注释内容, 说明gate使用这里的IP作为客户端连入IP. 相信绝大多数人都不会再去Google或者发Issue了. 勤翻阅文档是好事, 但如果能就地解决问题, 岂不是更能节省双方的时间吗.

ETiV avatar Mar 28 '13 21:03 ETiV

嗯, 很有道理, 的确 0.0.0.0更好一点。 不过配置文件除了json之外确实想不出更好的方案。。。

2013/3/29 ETiV [email protected]

Pomelo模板下, servers.json 配置文件中的host, 推荐改成0.0.0.0, 而不是现在的127.0.0.1. 多数有经验的程序员/系统管理员, 看到这个配置, 会以为程序只驻守127.0.0.1网络地址. 而修改后, 更符合思维惯性. (同时 starter.js里的isLocal也应一并修改.) 2.

在game-server/app.js中, 除非大部分client库都已支持Pomelo 0.3版本的新协议, 否则不推荐默认代码中直接使用 hybirdconnector和数据压缩配置. 而应在app.js及entryHandler.js中加以注释, 告知用户可以切换到 hybirdconnector的条件. 3.

感觉用json文件作为配置文件有一点不好, 没法插入评论. 导致很多才接触Pomelo的人对着初始化新项目后的配置文件手足无措. 比如第一条建议中出现的情况. 更多的发生在带有gate服务器, 用来负载均衡的时候. 人们不知道怎么设置. 而如果此时在"connector"后面加入注释内容, 说明gate使用这里的IP作为客户端连入IP. 相信绝大多数人都不会再去Google或者发Issue了. 勤翻阅文档是好事, 但如果能就地解决问题, 岂不是更能节省双方的时间吗.

— Reply to this email directly or view it on GitHubhttps://github.com/NetEase/pomelo-cn/issues/160 .

xiecc avatar Mar 29 '13 03:03 xiecc

本来在看YAML的,但受 events.js 启发,我将chat demo 的 servers.json 改成下面格式,文件扩展名改用.js

module.exports = {
  /**
  * 开发环境配置
  */
  "development":{
    // 如需对外开放,可将下面配置的127.0.0.1改成你网卡的IP地址。production环境同理。
    // 此IP将由gate服务器发送出去。
    "connector":[
      {"id":"connector-server-1", "host":"127.0.0.1", "port":4050, "clientPort": 3050, "frontend": true},
      {"id":"connector-server-2", "host":"127.0.0.1", "port":4051, "clientPort": 3051, "frontend": true},
      {"id":"connector-server-3", "host":"127.0.0.1", "port":4052, "clientPort": 3052, "frontend": true}
    ],
    // 修改结束
    "chat":[
      {"id":"chat-server-1", "host":"127.0.0.1", "port":6050},
      {"id":"chat-server-2", "host":"127.0.0.1", "port":6051},
      {"id":"chat-server-3", "host":"127.0.0.1", "port":6052}
    ],
    "gate":[
      {"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true}
    ]
  },
  /**
   * 生产环境配置
   */
  "production":{
    "connector":[
      {"id":"connector-server-1", "host":"127.0.0.1", "port":4050, "clientPort": 3050, "frontend": true},
      {"id":"connector-server-2", "host":"127.0.0.1", "port":4051, "clientPort": 3051, "frontend": true},
      {"id":"connector-server-3", "host":"127.0.0.1", "port":4052, "clientPort": 3052, "frontend": true}
    ],
    "chat":[
      {"id":"chat-server-1", "host":"127.0.0.1", "port":6050},
      {"id":"chat-server-2", "host":"127.0.0.1", "port":6051},
      {"id":"chat-server-3", "host":"127.0.0.1", "port":6052}
    ],
    "gate":[
      {"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true}
    ]
  }
};

同时修改了加载配置文件的appUtil.jsloadServers部分,成为:

app.loadConfig('servers', app.getBase() + '/config/servers.js');
// 或没有最后的 .js。node会自动扫描.js/.json/.node,自动兼容旧版配置扩展名。
// http://nodejs.org/api/modules.html#modules_file_modules

程序运行不受任何影响,除引入文件的路径外,载入配置文件的逻辑代码不需修改。 配置数据部分仍旧使用JSON的结构,便于js开发人员理解,而且可以使用注释。

而对于当前项目的升级,可以写一个JS小工具。

var content = fs.readFileSync(src_filename_ext_json).toString('utf8');
content = 'module.exports = ' + content.substr(0, content.length - 1) + ';';
fs.writeFileSync(dst_filename_ext_js, content);

或者简单的 echo cat 命令组合完成无痛升级。

#!/bin/bash

OLD_JSON="$1"
NEW_JS="$2"

echo -n 'module.exports = ' > $NEW_JS && cat $OLD_JSON >> $NEW_JS && echo ';' >> $NEW_JS

*升级工具需要扫描配置文件目录,给出新配置文件的文件名,以及新配置的载入,同旧版本进行比较、测试。

ETiV avatar Mar 29 '13 08:03 ETiV

@ETiV JSON 作为配置文件不能注释是个很头疼的问题,所以我最近写了一个包,来让JSON 支持 注释,可以试用一下 https://github.com/numbcoder/json-comments

numbcoder avatar Mar 29 '13 09:03 numbcoder

JSON 作为配置文件不能注释是个很头疼的问题,所以我最近写了一个包,来让JSON 支持 注释,可以试用一下

不错哦,这个屌

ETiV avatar Mar 29 '13 09:03 ETiV

@不过配置文件除了json之外确实想不出更好的方案。。。 https://github.com/mojombo/toml

sonygod avatar Mar 31 '13 03:03 sonygod

json对于使用javascript来说是最适合的,没有之一

phodal avatar Oct 13 '13 06:10 phodal