WIP: status endpoint and error page

This commit is contained in:
Mark Silva 2023-09-01 13:51:19 +08:00
parent f51169d691
commit 5819dc411b
4 changed files with 102 additions and 70 deletions

2
auto-imports.d.ts vendored
View File

@ -4,5 +4,5 @@
// Generated by unplugin-auto-import
export {}
declare global {
const ElNotification: typeof import('element-plus/es')['ElNotification']
}

View File

@ -3,7 +3,7 @@ import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import App from './App.vue'
import router from './router'
import appRouter from './router'
import { createI18n } from 'vue-i18n'
import { languages, defaultLocale } from './language'
@ -13,7 +13,12 @@ import {
cacheDoc as cacheResourceDocsDoc
} from './obp/resource-docs'
import { cache as cacheMessageDocs, cacheDoc as cacheMessageDocsDoc } from './obp/message-docs'
import { version as configVersion, getMyAPICollections, getMyAPICollectionsEndpoint } from './obp'
import {
version as configVersion,
getMyAPICollections,
getMyAPICollectionsEndpoint,
checkServerStatus
} from './obp'
import { getOBPGlossary } from './obp/glossary'
import 'element-plus/dist/index.css'
@ -23,7 +28,38 @@ import '@fontsource/roboto/400.css'
import '@fontsource/roboto/700.css'
;(async () => {
const app = createApp(App)
const router = await appRouter()
try {
const isServerActive = false //(await checkServerStatus())
//if (isServerActive) await setupData(app)
const messages = Object.assign(languages)
const i18n = createI18n({
locale: defaultLocale,
fallbackLocale: 'ES',
messages
})
app.provide('i18n', i18n)
app.use(ElementPlus)
app.use(i18n)
app.use(createPinia())
app.use(router)
app.mount('#app')
if (!isServerActive) router.replace({ path: 'error' })
app.config.errorHandler = (error) => {
console.log(error)
router.replace({ path: 'error' })
}
} catch (error) {
console.log(error)
router.replace({ path: 'error' })
}
})()
async function setupData(app: App<Element>) {
const worker = new Worker('/js/worker/web-worker.js')
const resourceDocsCache = await caches.open('obp-resource-docs-cache')
const resourceDocsCacheResponse = await resourceDocsCache.match('/operationid')
@ -68,19 +104,4 @@ import '@fontsource/roboto/700.css'
} else {
app.provide('OBP-MyCollectionsEndpoint', undefined)
}
const messages = Object.assign(languages)
const i18n = createI18n({
locale: defaultLocale,
fallbackLocale: 'ES',
messages
})
app.provide('i18n', i18n)
app.use(ElementPlus)
app.use(i18n)
app.use(createPinia())
app.use(router)
app.mount('#app')
})()
}

View File

@ -3,12 +3,17 @@ import superagent from 'superagent'
export const version = import.meta.env.VITE_OBP_API_VERSION
const default_collection_name = 'Favourites'
export async function checkServerStatus(): Promise<boolean> {
const status = (await superagent.get(`/api/status`)).body['status']
return status
}
export async function get(path: string): Promise<any> {
try {
return (await superagent.get(`/api/get?path=${path}`)).body
} catch (error) {
console.log(error)
return error
return { error }
}
}
@ -17,7 +22,7 @@ export async function create(path: string, body: any): Promise<any> {
return (await superagent.post(`/api/create?path=${path}`).send(JSON.parse(body))).body
} catch (error) {
console.log(error)
return error
return { error }
}
}
@ -26,7 +31,7 @@ export async function update(path: string, body: any): Promise<any> {
return (await superagent.put(`/api/update?path=${path}`).send(JSON.parse(body))).body
} catch (error) {
console.log(error)
return error
return { error }
}
}
@ -35,7 +40,7 @@ export async function discard(path: string): Promise<any> {
return (await superagent.delete(`/api/delete?path=${path}`)).body
} catch (error) {
console.log(error)
return error
return { error }
}
}
@ -44,6 +49,7 @@ export async function getCurrentUser(): Promise<any> {
return (await superagent.get(`/api/user/current`)).body
} catch (error) {
console.log(error)
return { error }
}
}

View File

@ -5,52 +5,57 @@ import BodyView from '../views/BodyView.vue'
import Content from '../components/Content.vue'
import Preview from '../components/Preview.vue'
import NotFoundView from '../views/NotFoundView.vue'
import InternalServerErrorView from '../views/InternalServerErrorView.vue'
import { checkServerStatus } from '../obp'
const router = createRouter({
history: createWebHistory(),
mode: 'history',
routes: [
{
path: '/',
redirect: '/operationid'
},
{
path: '/glossary',
name: 'glossary',
component: GlossaryView
},
{
path: '/message-docs/:id',
name: 'message-docs',
component: MessageDocsView
},
{
path: '/operationid',
name: 'operationid',
component: BodyView
},
{
path: '/operationid/:id',
name: 'operationid-path',
component: BodyView,
children: [
{
path: '',
name: 'api',
components: {
body: Content,
preview: Preview
export default async function router(): Promise<any> {
const isServerUp = false //await checkServerStatus()
const router = createRouter({
history: createWebHistory(),
mode: 'history',
routes: [
{
path: '/',
redirect: isServerUp ? '/operationid' : '/error'
},
{
path: '/glossary',
name: 'glossary',
component: isServerUp ? GlossaryView : InternalServerErrorView
},
{
path: '/message-docs/:id',
name: 'message-docs',
component: isServerUp ? MessageDocsView : InternalServerErrorView
},
{
path: '/operationid',
name: 'operationid',
component: isServerUp ? BodyView : InternalServerErrorView
},
{
path: '/operationid/:id',
name: 'operationid-path',
component: BodyView,
children: [
{
path: '',
name: 'api',
components: {
body: Content,
preview: Preview
}
}
}
]
},
{
path: '/callback',
name: 'callback',
component: BodyView
},
{ path: '/:pathMatch(.*)*', name: 'notFound', component: NotFoundView }
]
})
export default router
]
},
{
path: '/callback',
name: 'callback',
component: isServerUp ? BodyView : InternalServerErrorView
},
{ path: '/error', name: 'error', component: InternalServerErrorView },
{ path: '/:pathMatch(.*)*', name: 'notFound', component: NotFoundView }
]
})
return router
}