mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-20 23:11:42 +01:00
Implement maintenance
This commit is contained in:
23
src/middleware/maintenance.global.ts
Normal file
23
src/middleware/maintenance.global.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
let isMaintenance = ref<Boolean>(true)
|
||||
const { $trpc } = useNuxtApp()
|
||||
|
||||
try {
|
||||
isMaintenance.value = await $trpc.maintenance.is.query()
|
||||
} catch (error) {
|
||||
return navigateTo('/maintenance')
|
||||
}
|
||||
|
||||
if (isMaintenance.value && to.path !== '/maintenance') {
|
||||
return navigateTo('/maintenance', {
|
||||
redirectCode: 301,
|
||||
})
|
||||
}
|
||||
|
||||
if (!isMaintenance.value && to.path === '/maintenance') {
|
||||
return navigateTo('/', {
|
||||
redirectCode: 301,
|
||||
replace: true,
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user