add demo template
This commit is contained in:
8
src/app.ts
Normal file
8
src/app.ts
Normal 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
16
src/demo-route.ts
Normal 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
8
src/index.ts
Normal 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}`);
|
||||
});
|
||||
Reference in New Issue
Block a user