feat: Refactor server implementation to support Bun and Node environments

- Introduced `ServerNode` and `BunServer` classes to handle server logic for Node and Bun respectively.
- Updated `App` class to initialize the appropriate server based on the runtime environment.
- Enhanced `parseBody` function to handle request body parsing for both environments.
- Modified WebSocket handling to support Bun's WebSocket upgrade mechanism.
- Improved error handling and response structure across the server implementation.
- Added support for custom middleware in the server's request handling.
- Refactored server base functionality into `ServerBase` for better code organization.
- Updated type definitions to reflect changes in server options and listener handling.
- Added a new demo for testing the server functionality with various request types.
This commit is contained in:
2025-12-20 05:11:51 +08:00
parent e1a53c01ea
commit a6a7e74559
21 changed files with 1173 additions and 454 deletions

25
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@kevisual/router",
"version": "0.0.39",
"version": "0.0.41",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@kevisual/router",
"version": "0.0.39",
"version": "0.0.41",
"license": "MIT",
"dependencies": {
"path-to-regexp": "^8.3.0",
@@ -20,6 +20,7 @@
"@rollup/plugin-commonjs": "29.0.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-typescript": "^12.3.0",
"@types/bun": "^1.3.5",
"@types/node": "^25.0.3",
"@types/send": "^1.2.1",
"@types/ws": "^8.18.1",
@@ -729,6 +730,16 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/bun": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.3.5.tgz",
"integrity": "sha512-RnygCqNrd3srIPEWBd5LFeUYG7plCoH2Yw9WaZGyNmdTEei+gWaHqydbaIRkIkcbXwhBT94q78QljxN0Sk838w==",
"dev": true,
"license": "MIT",
"dependencies": {
"bun-types": "1.3.5"
}
},
"node_modules/@types/eslint": {
"version": "9.6.1",
"dev": true,
@@ -1132,6 +1143,16 @@
"license": "MIT",
"peer": true
},
"node_modules/bun-types": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.3.5.tgz",
"integrity": "sha512-inmAYe2PFLs0SUbFOWSVD24sg1jFlMPxOjOSSCYqUgn4Hsc3rDc7dFvfVYjFPNHtov6kgUeulV4SxbuIV/stPw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/bytestreamjs": {
"version": "2.0.1",
"license": "BSD-3-Clause",