mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-14 12:14:42 +01:00
25 lines
572 B
TypeScript
25 lines
572 B
TypeScript
export default defineNuxtRouteMiddleware(async (to) => {
|
|
const isMaintenance = ref<boolean>(true)
|
|
try {
|
|
await $fetch('/api/maintenance').then((maintenance) => {
|
|
isMaintenance.value = maintenance.enabled
|
|
})
|
|
}
|
|
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
|
|
})
|
|
}
|
|
})
|