init router

This commit is contained in:
2024-10-16 00:47:30 +08:00
commit 733677f3f3
32 changed files with 2185 additions and 0 deletions

41
demo/simple/src/app-02.ts Normal file
View File

@@ -0,0 +1,41 @@
import { App } from '@abearxiong/router';
const app = new App();
app.listen(4002, () => {
console.log('Server is running at http://localhost:4002');
});
const callback = (req, res) => {
if (req.url.startsWith('/api/v')) {
// 在这里处理 /api/v 的请求
// res.writeHead(200, { 'Content-Type': 'text/plain' });
setTimeout(() => {
res.end('Intercepted /api/v request');
}, 2000);
}
};
app.server.on(callback);
new app.Route('demo', '01')
.define(async (ctx) => {
ctx.body = '01';
return ctx;
})
.addTo(app);
app
.route('demo')
.define(async (ctx) => {
ctx.body = '02';
return ctx;
})
.addTo(app);
app
.route('demo', '03')
.define(async (ctx) => {
ctx.body = '03';
return ctx;
})
.addTo(app);