-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (36 loc) · 958 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable import/order */
const { getOptions } = require('./src/utils/index.js')
const fastify = require('fastify')({
logger: {
transport: {
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss',
ignore: 'pid,hostname,level,req.remoteAddress,req.remotePort,reqId',
},
serializers: {
res(reply) {
// The default
return {
statusCode: reply.statusCode,
}
},
},
},
},
})
// Declare a route
fastify.register(require('./routes/index.js'))
// Run the server!
let { port } = getOptions()
const regPort = process.argv[process.argv.length - 1].match(/\d+/g)
port = port || (regPort && regPort[0]) || 5050
fastify.listen({ port }, (err, _address) => {
if (err) {
fastify.log.error(err)
process.exit(1)
}
// 打印已添加的全部路由
console.log(fastify.printRoutes())
// Server is now listening on ${address}
})