How to config server to serve /api ?
[issue link]https://nuxtjs.org/api/configuration-servermiddleware shows if I define handler function in serverMiddleware spec, I can do that. But the question is how? Here’s my setup:
server.js:
const
fastify = require('fastify')
,{Nuxt, Builder} = require('nuxt')
,config = require('./nuxt.config.js')
,host = process.env.HOST || '127.0.0.1'
,port = process.env.PORT || 3000
,nuxt = new Nuxt(config)
,app = fastify()
// Enable live build & reloading on dev
if (config.dev) {
new Builder(nuxt).build()
}
// __ONLY one of these work as they conflict__:
// app.register(require('./api/index'), {prefix: '/api'})
// app.use(nuxt.render)
app.listen(port, host)
api/index.js:
module.exports = async function (fastify, opts, next) {
fastify.get('/', (req, reply) => {
reply.send({ hello: 'world' })
})
}
thanks.