Add prefix to all api's in hapi

心已入冬 提交于 2019-12-11 19:02:14

问题


I have this code written in index.js file. My api's are running successfully on the / path. Now I need add a prefix to all my api's. I don't want to add one by one by editing each file. I need to do in one go.

composer((err, server) => {
  if (err) throw err

  server.initialize((errInit) => {
    if (err) throw errInit
    server.register({
      register: require('hapi-cron'),
      routes: { prefix: '/api' },
      options: {
        jobs: []
      }  
    }, (err) => {
      server.start(() => {
        const env = process.env.NODE_ENV
        const msg = `${env} server started at ${server.info.uri}`
        server.log(['server', 'info'], msg)
        if (_.includes(['sandbox', 'production'], env)) {
        }
      })    
    })   
  })
})

How Can I do this? Thank in advance!!!

来源:https://stackoverflow.com/questions/54516579/add-prefix-to-all-apis-in-hapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!