Skip to content

Commit

Permalink
优化middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbbbbbbbbbbba committed Feb 4, 2024
1 parent f503153 commit a3e29c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 17 additions & 6 deletions site/src/middleware/fetch.global.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
export default defineNuxtRouteMiddleware(async () => {
const configStore = useConfigStore()
const userStore = useUserStore()
await Promise.all([
configStore.fetchConfig(),
userStore.fetchCurrent(),
])

const load = async () => {
const configStore = useConfigStore()
const userStore = useUserStore()
await Promise.all([
configStore.fetchConfig(),
userStore.fetchCurrent(),
])
}

const nuxtApp = useNuxtApp()

// 服务端渲染,或者客服端渲染
if (process.server || (process.client && !nuxtApp.isHydrating)) {
await load()
}

})
3 changes: 3 additions & 0 deletions site/src/server/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default defineEventHandler(async (event) => {
console.log('New request: ' + getRequestURL(event))
})

0 comments on commit a3e29c1

Please sign in to comment.