This commit is contained in:
2025-12-02 09:00:25 +08:00
commit 081add5316
43 changed files with 8641 additions and 0 deletions

7
backend/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
backend/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);

21
backend/src/demo.ts Normal file
View File

@@ -0,0 +1,21 @@
import { App } from '@kevisual/router';
const app = new App();
app.route({
description: 'Demo route',
id: 'abc'
}).define(async (ctx) => {
ctx.body = 'Hello, Kevisual Router!';
}).addTo(app);
app.router.createRouteList()
app.call({
path: 'route',
key: 'list'
}).then((res) => {
console.log('Registered res:', res);
}).catch((error) => {
console.error('Error fetching res:', error);
});

4
backend/src/index.ts Normal file
View File

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

17
backend/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);
}

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');
};

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);
}