1

我的 server.js 中有以下代码:

throw new Error('The databasenumber was wrong, or you didn\'t bind one.' + process.env.VCAP_SERVICES + " === " + process.env.VCAP_SERVICES["mysql-5.1"]);

此时的输出是:

node.js:201
    throw e; // process.nextTick error, or 'error' event on first tick
          ^
Error: The databasenumber was wrong, or you didn't bind one.{"mysql-5.1":[{"name":"squarific-data","label":"mysql-5.1","plan":"free","tags":["mysql","mysql-5.1","relational","mysql-5.1","mysql"],"credentials":{"name":"d3d440f0f5eef44ceb9c5e27a94666b58","hostname":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","host":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","port":3306,"user":"uzb6UEDnb5huk","username":"uzb6UEDnb5huk","password":"***"}}]} === undefined
at Object.<anonymous> (/mnt/var/vcap.local/dea/apps/squarific-0-230c9a683dff6b045aa2a237ae9bf515/app/server.js:12:9)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)

虽然这当然应该是:

node.js:201
    throw e; // process.nextTick error, or 'error' event on first tick
          ^
Error: The databasenumber was wrong, or you didn't bind one.{"mysql-5.1":[{"name":"squarific-data","label":"mysql-5.1","plan":"free","tags":["mysql","mysql-5.1","relational","mysql-5.1","mysql"],"credentials":{"name":"d3d440f0f5eef44ceb9c5e27a94666b58","hostname":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","host":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","port":3306,"user":"uzb6UEDnb5huk","username":"uzb6UEDnb5huk","password":"***"}}]} === [{"name":"squarific-data","label":"mysql-5.1","plan":"free","tags":["mysql","mysql-5.1","relational","mysql-5.1","mysql"],"credentials":{"name":"d3d440f0f5eef44ceb9c5e27a94666b58","hostname":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","host":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","port":3306,"user":"uzb6UEDnb5huk","username":"uzb6UEDnb5huk","password":"***"}}]
at Object.<anonymous> (/mnt/var/vcap.local/dea/apps/squarific-0-230c9a683dff6b045aa2a237ae9bf515/app/server.js:12:9)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)

它不应该是未定义的,因为您可以清楚地看到 ["mysql-5.1"] 实际上是一个数组。我不知道它为什么会出现这种奇怪的行为,而且我在任何地方都找不到它为什么会这样做。

4

1 回答 1

0

服务变量作为 JSON 字符串而不是 appfog 的对象传递。

于 2012-12-06T06:05:40.200 回答