feat: add simple router

This commit is contained in:
2024-11-16 23:10:54 +08:00
parent 926c0a09cd
commit 5e38740c7b
5 changed files with 118 additions and 752 deletions

View File

@@ -0,0 +1,28 @@
import { SimpleRouter } from '@kevisual/router/simple';
const router = new SimpleRouter();
router.get('/', async (req, res) => {
console.log('get /');
});
router.post('/post', async (req, res) => {
console.log('post /post');
});
router.get('/user/:id', async (req, res) => {
console.log('get /user/:id', req.params);
});
router.post('/user/:id', async (req, res) => {
console.log('post /user/:id', req.params);
});
router.post('/user/:id/a', async (req, res) => {
console.log('post /user/:id', req.params);
});
router.parse({ url: 'http://localhost:3000/', method: 'GET' } as any, {} as any);
router.parse({ url: 'http://localhost:3000/post', method: 'POST' } as any, {} as any);
router.parse({ url: 'http://localhost:3000/user/1/a', method: 'GET' } as any, {} as any);
router.parse({ url: 'http://localhost:3000/user/1/a', method: 'POST' } as any, {} as any);