I'm trying to load a simple api written with nodejs
and fastify
, as seen in the code below.
When I try to open the page I get such an error in the logs
, and the page gives me Application
error.
Can you give me a hand?
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}`)
})
Procfile
web: node src/index.js
worker: node src/index.js
To let Fastify works on herouku you need to listen for all the incoming IPs:
fastify.listen(process.env.PORT, '0.0.0.0', (err, address) => {
if (err) throw err
fastify.log.info(`server listening on ${address}`)
})
I would suggest setting the logger to read some insight into your server
const fastify = require('fastify')({ logger: process.env.LOG_LEVEL || false })
to turn on/off more verbose logging when needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.