Nuxt/packages/app/template/middleware.js

19 lines
552 B
JavaScript
Raw Normal View History

2017-02-03 14:09:27 +00:00
<% if (middleware) { %>
const files = require.context('@/<%= dir.middleware %>', false, /^\.\/(?!<%= ignorePrefix %>)[^.]+\.(<%= extensions %>)$/)
const filenames = files.keys()
2017-02-03 14:09:27 +00:00
function getModule (filename) {
const file = files(filename)
return file.default || file
2017-02-03 14:09:27 +00:00
}
const middleware = {}
2017-02-03 14:09:27 +00:00
// Generate the middleware
for (const filename of filenames) {
const name = filename.replace(/^\.\//, '').replace(/\.(<%= extensions %>)$/, '')
2017-02-03 14:09:27 +00:00
middleware[name] = getModule(filename)
}
export default middleware
<% } else { %>export default {}<% } %>