Nuxt/test/fixtures/module/modules/middleware/index.js

23 lines
587 B
JavaScript
Raw Normal View History

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!')
}
})
// Add local middleware js
2017-06-29 17:00:18 +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-06-29 17:00:18 +00:00
this.addServerMiddleware('@modules/middleware/midd1')
2017-05-14 23:01:41 +00:00
resolve()
2017-05-14 22:45:01 +00:00
})
}