chore init project

This commit is contained in:
Benjamin Wegener
2024-04-02 15:57:41 +00:00
commit d161d8826e
10 changed files with 419 additions and 0 deletions

30
src/index.js Normal file
View File

@@ -0,0 +1,30 @@
import WetSock from './WetSock';
import { resolve } from 'path';
const wetsock = new WetSock();
const server = Bun.serve({
port: process.env.APP_PORT || 43_069,
fetch(req, server) {
const url = new URL(req.url);
if(url.pathname == '/chat') return wetsock.handleFetch(req, server);
if(url.pathname == '/client.js') {
const filePath = resolve(__dirname, 'WetSock', 'Client', 'Client.js');
const file = Bun.file(filePath);
return new Response(file);
}
const filePath = resolve(__dirname, 'views', 'index.html');
const file = Bun.file(filePath);
return new Response(file);
},
websocket: {
open: wetsock.handleOpen.bind(wetsock),
close: wetsock.handleClose.bind(wetsock),
message: wetsock.handleMessage.bind(wetsock),
drain: wetsock.handleDrain.bind(wetsock),
}
});
wetsock.start(server);