Skip to content

Commit

Permalink
refactor: use elysiajs to provide static files
Browse files Browse the repository at this point in the history
  • Loading branch information
ikxin committed Apr 16, 2024
1 parent 4a19201 commit 621aff3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 156 deletions.
Binary file modified bun.lockb
Binary file not shown.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"author": "一纸忘忧 <i@ikxin.com>",
"type": "module",
"scripts": {
"web-dev": "bun --watch service",
"build": "vite build",
"dev": "vite",
"service": "bun --watch service/index.ts",
Expand All @@ -16,11 +17,13 @@
},
"dependencies": {
"@arco-design/web-vue": "^2.55.0",
"@elysiajs/static": "^1.0.2",
"@vueuse/core": "^10.9.0",
"@vueuse/integrations": "^10.9.0",
"axios": "^1.6.8",
"dayjs": "^1.11.10",
"echarts": "^5.5.0",
"elysia": "^1.0.13",
"less": "^4.2.0",
"markdown-it-shiki": "^0.9.0",
"pinia": "^2.1.7",
Expand All @@ -36,6 +39,8 @@
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"@vitejs/plugin-vue": "^5.0.4",
"drizzle-kit": "^0.20.14",
"drizzle-orm": "^0.30.8",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-vue": "^9.23.0",
Expand Down
42 changes: 18 additions & 24 deletions service/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import { PrismaClient } from '@prisma/client'
import { execFile, ExecFileException } from 'child_process'
import { Elysia } from 'elysia'
import { staticPlugin } from '@elysiajs/static'

const prisma = new PrismaClient()

const servers = await prisma.server.findMany()

const getData = domain => {
return new Promise<{
error: ExecFileException | null
stdout: string
stderr: string
}>(resolve => {
execFile(
'./service/vlmcs/vlmcs-darwin',
[`${domain}:${1688}`, `-${6}`, `-l ${1}`],
{ timeout: 5 * 1000 },
(error, stdout, stderr) => resolve({ error, stdout, stderr }),
)
new Elysia()
// .use(
// staticPlugin({
// assets: 'dist/assets',
// prefix: '/assets',
// }),
// )
// .get('/*', () => Bun.file('dist/index.html'))
.onError(ctx => {
if (ctx.code === 'NOT_FOUND') {
ctx.set.redirect = '/'
return ''
}
})
}

servers.map(async item => {
const result = await getData(item.address)
console.log(result)
})
.use(staticPlugin({ assets: 'dist', prefix: '/' }))
.get('/', () => Bun.file('dist/index.html'))
.listen(3000)
2 changes: 1 addition & 1 deletion src/components/custom-footer.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import * as dayjs from 'dayjs'
import dayjs from 'dayjs'
const currentYear = ref(dayjs().year())
Expand Down
2 changes: 1 addition & 1 deletion src/typings/imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ declare global {
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
const defineComponent: typeof import('vue')['defineComponent']
const defineLoader: typeof import('vue-router/auto')['defineLoader']
const definePage: typeof import('unplugin-vue-router/runtime')['_definePage']
const definePage: typeof import('unplugin-vue-router/runtime')['definePage']
const defineStore: typeof import('pinia')['defineStore']
const eagerComputed: typeof import('@vueuse/core')['eagerComputed']
const effectScope: typeof import('vue')['effectScope']
Expand Down
140 changes: 11 additions & 129 deletions src/typings/vue-router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,18 @@
// It's recommended to commit this file.
// Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry.

/// <reference types="unplugin-vue-router/client" />
declare module 'vue-router/auto-routes' {
import type {
RouteRecordInfo,
ParamValue,
ParamValueOneOrMore,
ParamValueZeroOrMore,
ParamValueZeroOrOne,
} from 'unplugin-vue-router/types'

import type {
// type safe route locations
RouteLocationTypedList,
RouteLocationResolvedTypedList,
RouteLocationNormalizedTypedList,
RouteLocationNormalizedLoadedTypedList,
RouteLocationAsString,
RouteLocationAsRelativeTypedList,
RouteLocationAsPathTypedList,

// helper types
// route definitions
RouteRecordInfo,
ParamValue,
ParamValueOneOrMore,
ParamValueZeroOrMore,
ParamValueZeroOrOne,

// vue-router extensions
_RouterTyped,
RouterLinkTyped,
RouterLinkPropsTyped,
NavigationGuard,
UseLinkFnTyped,

// data fetching
_DataLoader,
_DefineLoaderOptions,
} from 'unplugin-vue-router/types'

declare module 'vue-router/auto/routes' {
/**
* Route name map generated by unplugin-vue-router
*/
export interface RouteNamedMap {
'/': RouteRecordInfo<'/', '/', Record<never, never>, Record<never, never>>,
'/activate': RouteRecordInfo<'/activate', '/activate', Record<never, never>, Record<never, never>>,
Expand All @@ -50,100 +29,3 @@ declare module 'vue-router/auto/routes' {
'/tools': RouteRecordInfo<'/tools', '/tools', Record<never, never>, Record<never, never>>,
}
}

declare module 'vue-router/auto' {
import type { RouteNamedMap } from 'vue-router/auto/routes'

export type RouterTyped = _RouterTyped<RouteNamedMap>

/**
* Type safe version of `RouteLocationNormalized` (the type of `to` and `from` in navigation guards).
* Allows passing the name of the route to be passed as a generic.
*/
export type RouteLocationNormalized<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationNormalizedTypedList<RouteNamedMap>[Name]

/**
* Type safe version of `RouteLocationNormalizedLoaded` (the return type of `useRoute()`).
* Allows passing the name of the route to be passed as a generic.
*/
export type RouteLocationNormalizedLoaded<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[Name]

/**
* Type safe version of `RouteLocationResolved` (the returned route of `router.resolve()`).
* Allows passing the name of the route to be passed as a generic.
*/
export type RouteLocationResolved<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationResolvedTypedList<RouteNamedMap>[Name]

/**
* Type safe version of `RouteLocation` . Allows passing the name of the route to be passed as a generic.
*/
export type RouteLocation<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationTypedList<RouteNamedMap>[Name]

/**
* Type safe version of `RouteLocationRaw` . Allows passing the name of the route to be passed as a generic.
*/
export type RouteLocationRaw<Name extends keyof RouteNamedMap = keyof RouteNamedMap> =
| RouteLocationAsString<RouteNamedMap>
| RouteLocationAsRelativeTypedList<RouteNamedMap>[Name]
| RouteLocationAsPathTypedList<RouteNamedMap>[Name]

/**
* Generate a type safe params for a route location. Requires the name of the route to be passed as a generic.
*/
export type RouteParams<Name extends keyof RouteNamedMap> = RouteNamedMap[Name]['params']
/**
* Generate a type safe raw params for a route location. Requires the name of the route to be passed as a generic.
*/
export type RouteParamsRaw<Name extends keyof RouteNamedMap> = RouteNamedMap[Name]['paramsRaw']

export function useRouter(): RouterTyped
export function useRoute<Name extends keyof RouteNamedMap = keyof RouteNamedMap>(name?: Name): RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[Name]

export const useLink: UseLinkFnTyped<RouteNamedMap>

export function onBeforeRouteLeave(guard: NavigationGuard<RouteNamedMap>): void
export function onBeforeRouteUpdate(guard: NavigationGuard<RouteNamedMap>): void

export const RouterLink: RouterLinkTyped<RouteNamedMap>
export const RouterLinkProps: RouterLinkPropsTyped<RouteNamedMap>

// Experimental Data Fetching

export function defineLoader<
P extends Promise<any>,
Name extends keyof RouteNamedMap = keyof RouteNamedMap,
isLazy extends boolean = false,
>(
name: Name,
loader: (route: RouteLocationNormalizedLoaded<Name>) => P,
options?: _DefineLoaderOptions<isLazy>,
): _DataLoader<Awaited<P>, isLazy>
export function defineLoader<
P extends Promise<any>,
isLazy extends boolean = false,
>(
loader: (route: RouteLocationNormalizedLoaded) => P,
options?: _DefineLoaderOptions<isLazy>,
): _DataLoader<Awaited<P>, isLazy>

export {
_definePage as definePage,
_HasDataLoaderMeta as HasDataLoaderMeta,
_setupDataFetchingGuard as setupDataFetchingGuard,
_stopDataFetchingScope as stopDataFetchingScope,
} from 'unplugin-vue-router/runtime'
}

declare module 'vue-router' {
import type { RouteNamedMap } from 'vue-router/auto/routes'

export interface TypesConfig {
beforeRouteUpdate: NavigationGuard<RouteNamedMap>
beforeRouteLeave: NavigationGuard<RouteNamedMap>

$route: RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[keyof RouteNamedMap]
$router: _RouterTyped<RouteNamedMap>

RouterLink: RouterLinkTyped<RouteNamedMap>
}
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"moduleResolution": "Bundler",
"noEmit": true,
"paths": { "@/*": ["src/*"] },
"skipLibCheck": true
"skipLibCheck": true,
"strict": true
},
"include": ["**/*.vue", "**/*.ts", "**/*.d.ts"]
}

0 comments on commit 621aff3

Please sign in to comment.