2017-05-14 22:45:01 +00:00
|
|
|
|
|
|
|
module.exports = function middlewareModule (options) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
// Add /api endpoint
|
|
|
|
this.addServerMiddleware({
|
|
|
|
path: '/api',
|
|
|
|
handler (req, res, next) {
|
|
|
|
res.end('It works!')
|
|
|
|
}
|
|
|
|
})
|
2017-05-21 15:45:43 +00:00
|
|
|
// Add local middleware js
|
|
|
|
this.addServerMiddleware('~/modules/middleware/log.js')
|
2017-05-14 23:01:41 +00:00
|
|
|
// Add plain middleware
|
|
|
|
this.addServerMiddleware((req, res, next) => {
|
2017-05-21 17:18:26 +00:00
|
|
|
res.setHeader('x-nuxt', 'hello')
|
2017-05-14 23:01:41 +00:00
|
|
|
next()
|
|
|
|
})
|
2017-05-21 17:18:26 +00:00
|
|
|
// Add file middleware
|
|
|
|
this.addServerMiddleware('~/modules/middleware/midd1')
|
2017-05-14 23:01:41 +00:00
|
|
|
resolve()
|
2017-05-14 22:45:01 +00:00
|
|
|
})
|
|
|
|
}
|