jjw

写给自己的博客。 记录学习的点滴以备查。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

定义路由

Posted on 2023-07-12 17:43  jjw  阅读(12)  评论(0编辑  收藏  举报
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}
})

注册路由里可以定义路由前缀。