Add features: custom server and websocket. Minor refactoring
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import bunext from "../../dist"; // => @moduletrace/bunext
|
||||
|
||||
const development = process.env.NODE_ENV == "development";
|
||||
const port = process.env.PORT || 3700;
|
||||
|
||||
/**
|
||||
* Initialize Bunext
|
||||
*/
|
||||
await bunext.bunextInit();
|
||||
|
||||
/**
|
||||
* Start your custom server
|
||||
*/
|
||||
const server = Bun.serve({
|
||||
routes: {
|
||||
"/*": {
|
||||
async GET(req) {
|
||||
return await bunext.bunextRequestHandler({ req });
|
||||
},
|
||||
},
|
||||
},
|
||||
/**
|
||||
* Set this to prevent HMR timeout warnings in the
|
||||
* browser console in development mode.
|
||||
*/
|
||||
idleTimeout: development ? 0 : undefined,
|
||||
development,
|
||||
port,
|
||||
});
|
||||
|
||||
bunext.bunextLog.info(`Server running on http://localhost:${server.port} ...`);
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { BunextConfig } from "../../dist/types";
|
||||
import { BunextWebsocket } from "./websocket";
|
||||
|
||||
const config: BunextConfig = {
|
||||
websocket: BunextWebsocket,
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { WebSocketHandler } from "bun";
|
||||
|
||||
export const BunextWebsocket: WebSocketHandler<any> = {
|
||||
message(ws, message) {
|
||||
console.log(`WS Message => ${message}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user