This commit is contained in:
2025-11-25 09:36:03 +08:00
parent d5c2ed3d85
commit 10937addac
10 changed files with 839 additions and 6 deletions

7
src/app.ts Normal file
View File

@@ -0,0 +1,7 @@
import { App } from "@kevisual/router";
import { useContextKey } from "@kevisual/use-config/context";
export const app: App = useContextKey<App>('app', new App({
serverOptions: {
path: '/client/router'
}
}));

8
src/config.ts Normal file
View File

@@ -0,0 +1,8 @@
import path from 'node:path';
import fs from 'node:fs';
export const HOME = 'daily-question';
export const ROOT_DIR = path.resolve(process.cwd(), 'storage', HOME);

4
src/index.ts Normal file
View File

@@ -0,0 +1,4 @@
import { app } from './app.ts'
import './router/index.ts';
export { app }

17
src/main.ts Normal file
View File

@@ -0,0 +1,17 @@
import { app } from './app.ts'
import './router/index.ts';
import { HOME } from './config.ts';
import { proxyRoute, initProxy } from '@kevisual/local-proxy/proxy.ts';
export { app }
if (require.main === module) {
initProxy({
pagesDir: './public',
watch: true,
home: `/root/${HOME}`
});
app.listen(9000, () => {
console.log('Server is running on http://localhost:9000');
});
app.onServerRequest(proxyRoute);
}

8
src/module/utils.ts Normal file
View File

@@ -0,0 +1,8 @@
import { nanoid, customAlphabet } from "nanoid";
import dayjs from "dayjs";
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
export const generateId = () => customAlphabet(alphabet, 12)();
export const getTodayDate = (): string => {
return dayjs().format('YYYY-MM-DD');
};

15
src/routes/index.ts Normal file
View File

@@ -0,0 +1,15 @@
// base
import { app } from '../app.ts';
const hasAuth = app.router.routes.some(r => r.id === 'auth');
if (!hasAuth) {
console.log('添加认证中间件路由');
app.route({
path: 'auth',
key: 'auth',
description: '用户认证',
id: 'auth'
}).define(async (ctx) => {
// 这里可以添加实际的认证逻辑
}).addTo(app);
}