mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
19 lines
551 B
JavaScript
19 lines
551 B
JavaScript
<% if (middleware) { %>
|
|
const files = require.context('@/<%= dir.middleware %>', false, /^\.\/(?!<%= ignorePrefix %>)[^.]+\.(<%= extensions %>)$/)
|
|
const filenames = files.keys()
|
|
|
|
function getModule(filename) {
|
|
const file = files(filename)
|
|
return file.default || file
|
|
}
|
|
const middleware = {}
|
|
|
|
// Generate the middleware
|
|
for (const filename of filenames) {
|
|
const name = filename.replace(/^\.\//, '').replace(/\.(<%= extensions %>)$/, '')
|
|
middleware[name] = getModule(filename)
|
|
}
|
|
|
|
export default middleware
|
|
<% } else { %>export default {}<% } %>
|