Nuxt/lib/app/middleware.js
2018-01-05 13:18:11 +01:00

21 lines
548 B
JavaScript

<% if (middleware) { %>
let files = require.context('@/middleware', false, /^\.\/(?!<%= ignorePrefix %>).*\.(<%= extensions %>)$/)
let filenames = files.keys()
function getModule (filename) {
let file = files(filename)
return file.default
? file.default
: file
}
let middleware = {}
// Generate the middleware
for (let filename of filenames) {
let name = filename.replace(/^\.\//, '').replace(/\.(<%= extensions %>)$/, '')
middleware[name] = getModule(filename)
}
export default middleware
<% } else { %>export default {}<% } %>