mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 16:43:55 +00:00
21 lines
501 B
JavaScript
21 lines
501 B
JavaScript
<% if (middleware) { %>
|
|
let files = require.context('@/middleware', false, /^\.\/.*\.(js|ts)$/)
|
|
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(/\.(js|ts)$/, '')
|
|
middleware[name] = getModule(filename)
|
|
}
|
|
|
|
export default middleware
|
|
<% } else { %>export default {}<% } %>
|