mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-17 11:15:14 +00:00
9c1e0d1743
Co-authored-by: Clark Du <clark.duxin@gmail.com> Co-authored-by: Pooya Parsa <pooya@pi0.ir>
19 lines
552 B
JavaScript
19 lines
552 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 {}<% } %>
|