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

33 lines
865 B
JavaScript
Raw Normal View History

2024-04-02 15:57:41 +00:00
import { resolve } from 'path';
2024-04-02 23:30:37 +00:00
import WetSock from './WetSock';
2024-04-02 15:57:41 +00:00
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);
2024-04-02 15:57:41 +00:00
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);