繁体   English   中英

Nodejs fastify 崩溃 heruku api

[英]Nodejs fastify crash heruku api

我正在尝试加载一个用nodejsfastify编写的简单 api ,如下面的代码所示。

当我尝试打开页面时,我在logs中收到这样的错误,并且页面给了我Application错误。

你能帮我个忙吗?

at=error code=H10 desc="App crashed" method=GET path="/"... dyno= connect= service= status=503 bytes= protocol=https

package.json

{
  "name": "fastPro",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node src/index.js",
    "dev": "nodemon src/index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "fastify": "^3.11.0",
    "nodemon": "^2.0.7"
  }
}

index.js

const fastify = require('fastify')()

// Declare a route
fastify.get('/', (request, reply) => {
    reply.send({ hello: 'world!' })
})

// Run the server!
fastify.listen(process.env.PORT, (err, address) => {
    if (err) throw err
    fastify.log.info(`server listening on ${address}`)
})

档案

web: node src/index.js
worker: node src/index.js

要让 Fastify 在 herouku 上工作,你需要监听所有传入的 IP:

fastify.listen(process.env.PORT, '0.0.0.0', (err, address) => {
    if (err) throw err
    fastify.log.info(`server listening on ${address}`)
})

我建议设置记录器以读取对您的服务器的一些见解

const fastify = require('fastify')({ logger: process.env.LOG_LEVEL || false })

在需要时打开/关闭更详细的日志记录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM