Nuxt/test/fixtures/module/modules/middleware/index.js
Sébastien Chopin 0183ac4b86 Merge branch 'dev' of github.com:Atinux/nuxt.js into dev
Conflicts:
	lib/build.js
	lib/module.js
	lib/server.js
2017-05-21 19:23:31 +02:00

23 lines
589 B
JavaScript
Executable File

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
this.addServerMiddleware('~/modules/middleware/log.js')
// Add plain middleware
this.addServerMiddleware((req, res, next) => {
res.setHeader('x-nuxt', 'hello')
next()
})
// Add file middleware
this.addServerMiddleware('~/modules/middleware/midd1')
resolve()
})
}