findAddr.js 798 B

12345678910111213141516171819202122232425262728
  1. var findServer = function (hostConfig, serverName) {
  2. if (hostConfig === undefined) {
  3. console.log('===ERROR=== 获取服务器配置信息时发生错误,请检查服务器配置!!!\n')
  4. return ''
  5. }
  6. if (serverName === undefined) {
  7. console.log('===ERROR=== 函数传参错误,请检查服务器配置!!!\n')
  8. return ''
  9. }
  10. var targetServer = hostConfig[serverName]
  11. if (targetServer === undefined ) {
  12. console.log('===ERROR=== 服务' + serverName +'配置信息错误,请检查服务器配置!!!\n')
  13. return ''
  14. }
  15. var addr = ''
  16. if (targetServer.port === 0) {
  17. addr = targetServer.addr + targetServer.path
  18. } else {
  19. addr = targetServer.addr + ':' + targetServer.port.toString() + targetServer.path
  20. }
  21. return addr
  22. }
  23. module.exports = findServer