chore(example) introduce changes to example implementation

This commit is contained in:
gh0sTedBuddy
2024-04-07 20:08:40 +01:00
parent 675ef2c5a7
commit cf279d4a3e
2 changed files with 34 additions and 48 deletions

View File

@@ -1,24 +1,28 @@
import { resolve } from 'path';
import WetSock from './WetSock';
import RoomPlugin from './WetSock/Plugins/Rooms/RoomPlugin';
const wetsock = new WetSock();
const rooms = new RoomPlugin();
wetsock.registerPlugin('rooms', rooms);
const server = Bun.serve({
port: process.env.APP_PORT || 43_069,
fetch(req, server) {
port: process.env.APP_PORT || 3_000,
async fetch(req, server) {
const url = new URL(req.url);
if(url.pathname == '/chat') return wetsock.handleUpgrade(req, server);
let filePath = resolve(__dirname, 'WetSock', 'Client', 'Assets', 'index.html');
if(url.pathname == '/client.js') {
const filePath = resolve(__dirname, 'WetSock', 'Client', 'Client.js');
const file = Bun.file(filePath);
return new Response(file);
filePath = resolve(__dirname, 'WetSock', 'Client', 'Client.js');
}
const filePath = resolve(__dirname, 'views', 'index.html');
const file = Bun.file(filePath);
if(!(await file.exists())) {
return new Response('Not found', {status: 404});
}
return new Response(file);
},
websocket: {