2018-03-16 16:12:06 +00:00
|
|
|
export default function middlewareModule(options) {
|
2017-05-14 22:45:01 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
// Add /api endpoint
|
|
|
|
this.addServerMiddleware({
|
|
|
|
path: '/api',
|
2017-10-31 13:26:19 +00:00
|
|
|
handler(req, res, next) {
|
2017-05-14 22:45:01 +00:00
|
|
|
res.end('It works!')
|
|
|
|
}
|
|
|
|
})
|
2017-05-21 15:45:43 +00:00
|
|
|
// Add local middleware js
|
2017-07-06 22:27:27 +00:00
|
|
|
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
|
2017-07-06 22:27:27 +00:00
|
|
|
this.addServerMiddleware('~/modules/middleware/midd1')
|
2017-05-14 23:01:41 +00:00
|
|
|
resolve()
|
2017-05-14 22:45:01 +00:00
|
|
|
})
|
|
|
|
}
|