add demo template

This commit is contained in:
2025-02-20 13:39:45 +08:00
commit 9eb68a69d7
9 changed files with 3988 additions and 0 deletions

8
src/app.ts Normal file
View File

@@ -0,0 +1,8 @@
import { App } from '@kevisual/router';
import { useContextKey, useContext } from '@kevisual/use-config/context';
const init = () => {
return new App();
};
export const app = useContextKey('app', init);

16
src/demo-route.ts Normal file
View File

@@ -0,0 +1,16 @@
import { app } from './app.ts';
import { useConfig } from '@kevisual/use-config';
app
.route({
path: 'demo',
key: 'demo',
})
.define(async (ctx) => {
ctx.body = '123';
})
.addTo(app);
const config = useConfig();
console.log('run demo: http://localhost:' + config.port + '/api/router?path=demo&key=demo');

8
src/index.ts Normal file
View File

@@ -0,0 +1,8 @@
import { app } from './app.ts';
import { useConfig } from '@kevisual/use-config';
import './demo-route.ts';
const config = useConfig();
app.listen(config.port, () => {
console.log(`server is running at http://localhost:${config.port}`);
});