feat: mongodb readyState
This commit is contained in:
@ -1,13 +1,16 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import './styles/global.css'
|
import './styles/global.css'
|
||||||
|
|
||||||
|
const readyState = computedAsync(async () => await rpc.readyState())
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Html>
|
<Html>
|
||||||
<Body h-screen>
|
<Body h-screen>
|
||||||
<NuxtLayout>
|
<NuxtLayout v-if="readyState === 1">
|
||||||
<NuxtPage />
|
<NuxtPage />
|
||||||
</NuxtLayout>
|
</NuxtLayout>
|
||||||
|
<Connection v-else :connection="readyState" />
|
||||||
</Body>
|
</Body>
|
||||||
</Html>
|
</Html>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
34
client/components/Connection.vue
Normal file
34
client/components/Connection.vue
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
defineProps({
|
||||||
|
connection: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NPanelGrids>
|
||||||
|
<div flex="~ gap-2" animate-pulse items-center text-yellow>
|
||||||
|
<NIcon icon="carbon-flow-connection" />
|
||||||
|
Please check your mongodb connection
|
||||||
|
</div>
|
||||||
|
<div flex="~ gap-2" items-center text-light>
|
||||||
|
Your current connection is: {{ connection }}
|
||||||
|
</div>
|
||||||
|
<div absolute bottom-10 left-10 right-10 flex justify-around>
|
||||||
|
<NCard p2 text-red-5>
|
||||||
|
0: Not connected
|
||||||
|
</NCard>
|
||||||
|
<NCard p2 text-green-5>
|
||||||
|
1: Connected
|
||||||
|
</NCard>
|
||||||
|
<NCard p2 text-yellow-5>
|
||||||
|
2: Connecting
|
||||||
|
</NCard>
|
||||||
|
<NCard p2 text-orange-5>
|
||||||
|
3: Disconnecting
|
||||||
|
</NCard>
|
||||||
|
</div>
|
||||||
|
</NPanelGrids>
|
||||||
|
</template>
|
||||||
@ -2,10 +2,13 @@ import { logger } from '@nuxt/kit'
|
|||||||
import mongoose from 'mongoose'
|
import mongoose from 'mongoose'
|
||||||
import type { NuxtDevtoolsServerContext, ServerFunctions } from '../types'
|
import type { NuxtDevtoolsServerContext, ServerFunctions } from '../types'
|
||||||
|
|
||||||
export function setupDatabaseRPC({ nuxt, options }: NuxtDevtoolsServerContext): any {
|
export function setupDatabaseRPC({ options }: NuxtDevtoolsServerContext): any {
|
||||||
mongoose.connect(options.uri, options.options)
|
mongoose.connect(options.uri, options.options)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
async readyState() {
|
||||||
|
return mongoose.connection.readyState
|
||||||
|
},
|
||||||
async createCollection(name: string) {
|
async createCollection(name: string) {
|
||||||
return await mongoose.connection.db.createCollection(name)
|
return await mongoose.connection.db.createCollection(name)
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
export interface ServerFunctions {
|
export interface ServerFunctions {
|
||||||
// Database - collections
|
// Database - collections
|
||||||
|
readyState(): Promise<any>
|
||||||
createCollection(name: string): Promise<any>
|
createCollection(name: string): Promise<any>
|
||||||
listCollections(): Promise<any>
|
listCollections(): Promise<any>
|
||||||
getCollection(name: string): Promise<any>
|
getCollection(name: string): Promise<any>
|
||||||
@ -27,6 +28,6 @@ export interface Collection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Resource {
|
export interface Resource {
|
||||||
type: string
|
type: 'index' | 'create' | 'show' | 'put' | 'delete'
|
||||||
by?: string
|
by?: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user