add deno run script

This commit is contained in:
bobbydigitales
2024-11-08 09:46:19 -08:00
parent 6ce693cefc
commit 6c692c4b9f
13 changed files with 383 additions and 283 deletions

2
deno/go.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
sudo /root/.deno/bin/deno run --inspect --allow-all --unstable-temporal server.ts

View File

@@ -7,12 +7,21 @@
import { serveDir } from "jsr:@std/http/file-server"
const memoryCache = false;
const memoryResponseMap: Map<string, Response> = new Map();
// deno-lint-ignore-file prefer-const no-explicit-any
async function serveFile(filename: string) {
// console.log(filename)
if (!memoryCache) {
const file = await Deno.readFile("../" + filename);
const newResponse = new Response(file);
if (filename.endsWith('.js')) {
newResponse.headers.set('content-type', 'application/javascript')
}
return newResponse;
}
const response = memoryResponseMap.get(filename);
if (response) {
@@ -26,6 +35,7 @@ async function serveFile(filename: string) {
newResponse.headers.set('content-type', 'application/javascript')
}
console.log(`Caching: ${filename}`);
memoryResponseMap.set(filename, newResponse);
return newResponse.clone();
@@ -137,9 +147,9 @@ interface PeerMessage {
function peerMessageHandler(m: PeerMessage, _socket: WebSocket) {
console.log(`Peer message type ${m.message.type} from ${colorID(m.from)}:${m.from_peername}:${m.from_username} to ${colorID(m.to)}`)
console.log(`pm:${m.message.type} f:${colorID(m.from)}:${m.from_peername}:${m.from_username} t:${colorID(m.to)}`)
let toPeer = peerSockets.get(m.to);
const toPeer = peerSockets.get(m.to);
if (!toPeer) {
console.log(`Couln't find peer ${m.to}`)
return null;
@@ -151,7 +161,7 @@ function peerMessageHandler(m: PeerMessage, _socket: WebSocket) {
return null;
}
let messageToSend = JSON.stringify(m);
const messageToSend = JSON.stringify(m);
// console.log("ws->", toPeer, messageToSend);
toPeer.send(messageToSend)
return null;
@@ -256,7 +266,8 @@ function handler(request: Request, info: any) {
if (url.pathname.includes("/static/")) {
return serveDir(request, { fsRoot: "../" });
return serveFile(url.pathname);
// return serveDir(request, { fsRoot: "../" });
}
return serveFile("/static/index.html")