const routes = (fastify, options, done) => { fastify.post('/login', async (request, reply) => { return 'ok' }) fastify.get('/getBooks', async (request, reply) => { return 'OK' }) fastify.get('/getUsers', async (request, reply) => { return 'OK' }) done() } module.exports = routes
定义路由后,再引用
fastify.register(require('./routes/index'), { prefix: '/v1' }) //添加路由前缀 fastify.listen({ port: 8088, host: APP_IP}, (err, address) => { console.log(`app run ip: ${APP_IP}`); if (err) throw err // lServer is now listening on ${address} })注册路由里可以定义路由前缀。
标签:return,定义,err,request,fastify,reply,路由 From: https://www.cnblogs.com/Jiaojiawang/p/17548372.html