Nuxt/packages/vue-app/template/middleware.js

19 lines
551 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
2018-10-24 13:46:06 +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 {}<% } %>