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

22 lines
586 B
JavaScript
Raw Normal View History

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',
handler (req, res, next) {
2017-05-14 22:45:01 +00:00
res.end('It works!')
}
})
// 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
})
}