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:
@@ -2,9 +2,13 @@ export const isNode = typeof process !== 'undefined' && process.versions != null
|
||||
export const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && typeof document.createElement === 'function';
|
||||
// @ts-ignore
|
||||
export const isDeno = typeof Deno !== 'undefined' && typeof Deno.version === 'object' && typeof Deno.version.deno === 'string';
|
||||
// @ts-ignore
|
||||
export const isBun = typeof Bun !== 'undefined' && typeof Bun.version === 'string';
|
||||
|
||||
export const getEngine = () => {
|
||||
if (isNode) {
|
||||
if (isBun) {
|
||||
return 'bun';
|
||||
} else if (isNode) {
|
||||
return 'node';
|
||||
} else if (isBrowser) {
|
||||
return 'browser';
|
||||
|
||||
Reference in New Issue
Block a user