This repository has been archived on 2025-03-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
wetsock/lib/index.js
Benjamin Wegener ed6a254bbb chore cleanup
2024-04-02 23:30:37 +00:00

33 lines
865 B
JavaScript

import { resolve } from 'path';
import WetSock from './WetSock';
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.handleUpgrade(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);