Node.js为heroku构建json api

Ymo*_* Wu 6 javascript json heroku node.js express

我想通过node.js构建API,它在本地正常工作,但在云中失败.你能帮我找到这个bug吗?谢谢

https://infinite-gorge-6020.herokuapp.com

app.get('/', function(req, res) {
  res.render('index.ejs');
});

app.get('/host', function(req, res) {
  var sessionId = app.get('sessionId'),
      // generate a fresh token for this client
      token = opentok.generateToken(sessionId, { role: 'moderator' });

  res.json('host.ejs', {
    apiKey: apiKey,
    sessionId: sessionId,
    token: token
  });
Run Code Online (Sandbox Code Playgroud)

日志

2014-11-26T03:25:38.289313+00:00 heroku[router]: at=info method=GET path="/css/sample.css" host=infinite-gorge-6020.herokuapp.com request_id=18d8ce80-53a3-487f-94f5-a45f984bad67 fwd="1.171.57.36" dyno=web.1 connect=4ms service=6ms status=200 bytes=720
2014-11-26T03:25:39.207199+00:00 heroku[router]: http_error="Invalid HTTP status line" at=error code=H17 desc="Poorly formatted HTTP response" method=GET path="/host" host=infinite-gorge-6020.herokuapp.com request_id=a56aaf2e-7d2b-4479-bc01-3efd9542432b fwd="1.171.57.36" dyno=web.1 connect=1ms service=3ms status=503 bytes=639
2014-11-26T03:30:50+00:00 heroku[slug-compiler]: Slug compilation started
2014-11-26T03:30:55+00:00 heroku[slug-compiler]: Slug compilation finished
2014-11-26T03:30:55.675999+00:00 heroku[api]: Deploy cd3d6fe by kenshin0812@hotmail.com
2014-11-26T03:30:55.675999+00:00 heroku[api]: Release v16 created by kenshin0812@hotmail.com
2014-11-26T03:30:55.943650+00:00 heroku[web.1]: State changed from up to starting
2014-11-26T03:30:57.789085+00:00 heroku[web.1]: Starting process with command `node index.js`
2014-11-26T03:30:58.927452+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2014-11-26T03:30:59.218593+00:00 heroku[web.1]: State changed from starting to up
2014-11-26T03:30:59.079473+00:00 app[web.1]: Listening on , server_port 14730
2014-11-26T03:31:00.557311+00:00 heroku[web.1]: Process exited with status 143
2014-11-26T03:31:06.268233+00:00 heroku[router]: at=info method=GET path="/" host=infinite-gorge-6020.herokuapp.com request_id=824385d9-4aa9-439d-86a4-e8693d080e6b fwd="1.171.57.36" dyno=web.1 connect=1ms service=46ms status=200 bytes=2770
2014-11-26T03:31:06.529761+00:00 heroku[router]: at=info method=GET path="/css/sample.css" host=infinite-gorge-6020.herokuapp.com request_id=1f19e9ee-008f-4a33-b66a-bbd7f6b75bea fwd="1.171.57.36" dyno=web.1 connect=5ms service=9ms status=200 bytes=720
2014-11-26T03:31:08.043604+00:00 heroku[router]: http_error="Invalid HTTP status line" at=error code=H17 desc="Poorly formatted HTTP response" method=GET path="/host" host=infinite-gorge-6020.herokuapp.com request_id=bd19cbbe-bc58-4d4c-8426-d016e29555e1 fwd="1.171.57.36" dyno=web.1 connect=1ms service=6ms status=503 bytes=635
2014-11-26T03:31:08.041211+00:00 app[web.1]: Wed, 26 Nov 2014 03:31:08 GMT express deprecated res.json(status, obj): Use res.status(status).json(obj) instead at index.js:43:7
Run Code Online (Sandbox Code Playgroud)

作为日志,我添加状态并更改为

res.status(200).json
Run Code Online (Sandbox Code Playgroud)

还是不行,请帮忙,谢谢

小智 0

res.json([body])
Run Code Online (Sandbox Code Playgroud)

发送 JSON 响应。当传递对象或数组时,此方法与 res.send() 相同。

res.json(null)
res.json({ user: 'tobi' })
res.status(500).json({ error: 'message' })
Run Code Online (Sandbox Code Playgroud)

对于 json API 服务,您可能不需要渲染任何内容。