@dangao/bun-server 1.8.2 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/controller/controller.d.ts.map +1 -1
- package/dist/core/application.d.ts +5 -0
- package/dist/core/application.d.ts.map +1 -1
- package/dist/error/handler.d.ts.map +1 -1
- package/dist/events/event-module.d.ts +4 -0
- package/dist/events/event-module.d.ts.map +1 -1
- package/dist/events/types.d.ts +16 -0
- package/dist/events/types.d.ts.map +1 -1
- package/dist/index.js +5038 -4873
- package/dist/middleware/builtin/error-handler.d.ts.map +1 -1
- package/dist/middleware/builtin/logger.d.ts.map +1 -1
- package/dist/router/decorators.d.ts +10 -10
- package/dist/router/decorators.d.ts.map +1 -1
- package/dist/router/router.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/controller/controller.ts +10 -2
- package/src/core/application.ts +40 -0
- package/src/error/handler.ts +17 -0
- package/src/events/event-module.ts +108 -0
- package/src/events/types.ts +19 -0
- package/src/middleware/builtin/error-handler.ts +10 -0
- package/src/middleware/builtin/logger.ts +17 -0
- package/src/router/decorators.ts +15 -15
- package/src/router/router.ts +18 -1
- package/tests/controller/path-combination.test.ts +135 -0
|
@@ -483,6 +483,141 @@ describe('Controller Path Normalization', () => {
|
|
|
483
483
|
expect(data.success).toBe(true);
|
|
484
484
|
});
|
|
485
485
|
|
|
486
|
+
// 场景 a: @Controller() + @GET('test') / @POST('test') -> /test
|
|
487
|
+
test('scenario a: @Controller() with @GET("test") and @POST("test") should match /test', async () => {
|
|
488
|
+
@Controller()
|
|
489
|
+
class TestController {
|
|
490
|
+
@GET('test')
|
|
491
|
+
public getTest() {
|
|
492
|
+
return { method: 'GET', path: 'test' };
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
@POST('test')
|
|
496
|
+
public postTest() {
|
|
497
|
+
return { method: 'POST', path: 'test' };
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
app.registerController(TestController);
|
|
502
|
+
await app.listen();
|
|
503
|
+
|
|
504
|
+
const getRes = await fetch(`http://localhost:${port}/test`);
|
|
505
|
+
expect(getRes.status).toBe(200);
|
|
506
|
+
expect((await getRes.json()).method).toBe('GET');
|
|
507
|
+
|
|
508
|
+
const postRes = await fetch(`http://localhost:${port}/test`, { method: 'POST' });
|
|
509
|
+
expect(postRes.status).toBe(200);
|
|
510
|
+
expect((await postRes.json()).method).toBe('POST');
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// 场景 b: @Controller() + @GET('/test') / @POST('/test') -> /test
|
|
514
|
+
test('scenario b: @Controller() with @GET("/test") and @POST("/test") should match /test', async () => {
|
|
515
|
+
@Controller()
|
|
516
|
+
class TestController {
|
|
517
|
+
@GET('/test')
|
|
518
|
+
public getTest() {
|
|
519
|
+
return { method: 'GET', path: 'test' };
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
@POST('/test')
|
|
523
|
+
public postTest() {
|
|
524
|
+
return { method: 'POST', path: 'test' };
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
app.registerController(TestController);
|
|
529
|
+
await app.listen();
|
|
530
|
+
|
|
531
|
+
const getRes = await fetch(`http://localhost:${port}/test`);
|
|
532
|
+
expect(getRes.status).toBe(200);
|
|
533
|
+
expect((await getRes.json()).method).toBe('GET');
|
|
534
|
+
|
|
535
|
+
const postRes = await fetch(`http://localhost:${port}/test`, { method: 'POST' });
|
|
536
|
+
expect(postRes.status).toBe(200);
|
|
537
|
+
expect((await postRes.json()).method).toBe('POST');
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
// 场景 c: @Controller('') + @GET() / @POST() -> /
|
|
541
|
+
test('scenario c: @Controller("") with @GET() and @POST() should match /', async () => {
|
|
542
|
+
@Controller('')
|
|
543
|
+
class TestController {
|
|
544
|
+
@GET()
|
|
545
|
+
public getRoot() {
|
|
546
|
+
return { method: 'GET', path: '/' };
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
@POST()
|
|
550
|
+
public postRoot() {
|
|
551
|
+
return { method: 'POST', path: '/' };
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
app.registerController(TestController);
|
|
556
|
+
await app.listen();
|
|
557
|
+
|
|
558
|
+
const getRes = await fetch(`http://localhost:${port}/`);
|
|
559
|
+
expect(getRes.status).toBe(200);
|
|
560
|
+
expect((await getRes.json()).method).toBe('GET');
|
|
561
|
+
|
|
562
|
+
const postRes = await fetch(`http://localhost:${port}/`, { method: 'POST' });
|
|
563
|
+
expect(postRes.status).toBe(200);
|
|
564
|
+
expect((await postRes.json()).method).toBe('POST');
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
// 场景 d: @Controller() + @GET() / @POST() -> /
|
|
568
|
+
test('scenario d: @Controller() with @GET() and @POST() should match /', async () => {
|
|
569
|
+
@Controller()
|
|
570
|
+
class TestController {
|
|
571
|
+
@GET()
|
|
572
|
+
public getRoot() {
|
|
573
|
+
return { method: 'GET', path: '/' };
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
@POST()
|
|
577
|
+
public postRoot() {
|
|
578
|
+
return { method: 'POST', path: '/' };
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
app.registerController(TestController);
|
|
583
|
+
await app.listen();
|
|
584
|
+
|
|
585
|
+
const getRes = await fetch(`http://localhost:${port}/`);
|
|
586
|
+
expect(getRes.status).toBe(200);
|
|
587
|
+
expect((await getRes.json()).method).toBe('GET');
|
|
588
|
+
|
|
589
|
+
const postRes = await fetch(`http://localhost:${port}/`, { method: 'POST' });
|
|
590
|
+
expect(postRes.status).toBe(200);
|
|
591
|
+
expect((await postRes.json()).method).toBe('POST');
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// 场景 e: @Controller() + @GET('/') / @POST('/') -> /
|
|
595
|
+
test('scenario e: @Controller() with @GET("/") and @POST("/") should match /', async () => {
|
|
596
|
+
@Controller()
|
|
597
|
+
class TestController {
|
|
598
|
+
@GET('/')
|
|
599
|
+
public getRoot() {
|
|
600
|
+
return { method: 'GET', path: '/' };
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
@POST('/')
|
|
604
|
+
public postRoot() {
|
|
605
|
+
return { method: 'POST', path: '/' };
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
app.registerController(TestController);
|
|
610
|
+
await app.listen();
|
|
611
|
+
|
|
612
|
+
const getRes = await fetch(`http://localhost:${port}/`);
|
|
613
|
+
expect(getRes.status).toBe(200);
|
|
614
|
+
expect((await getRes.json()).method).toBe('GET');
|
|
615
|
+
|
|
616
|
+
const postRes = await fetch(`http://localhost:${port}/`, { method: 'POST' });
|
|
617
|
+
expect(postRes.status).toBe(200);
|
|
618
|
+
expect((await postRes.json()).method).toBe('POST');
|
|
619
|
+
});
|
|
620
|
+
|
|
486
621
|
// 测试所有场景在同一应用中同时工作
|
|
487
622
|
test('should handle all path normalization scenarios simultaneously', async () => {
|
|
488
623
|
@Controller('/')
|