Skip to content

Commit f120f45

Browse files
committed
documenting server.ts
1 parent a239499 commit f120f45

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

server.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import { WebSocket, isWebSocketCloseEvent, isWebSocketPingEvent } from 'https://
44
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
55
// deno-lint-ignore camelcase
66
import { BCC_Middleware } from "https://raw.githubusercontent.com/jcc10/oak_bundle-compile-cache_middleware/v1.0.2/mod.ts";
7+
8+
// This needs to get moved during the WebRTC update.
79
import * as AniTests from "./client-ts/test-animations.ts";
810

911
const parsedArgs = parse(Deno.args);
1012

1113
let rendererSocket: WebSocket | null;
14+
15+
// The test handler. Currently just hardcoded. (Most of the stuff this is handling should be moved to WebRTC)
1216
const socketHandler: handler = async function (socket: WebSocket, url: URL): Promise<void> {
1317
if (url.pathname == "/renderer"){
1418
rendererSocket = socket;
@@ -46,8 +50,11 @@ const socketHandler: handler = async function (socket: WebSocket, url: URL): Pro
4650
}
4751

4852
const app = new Application();
49-
const router = new Router();
53+
54+
// The websocket system.
5055
app.use(WebSocketMiddleware(socketHandler));
56+
57+
// Build, Compile, Cache middleware initialization.
5158
const bccMiddle = new BCC_Middleware({
5259
BCC_Settings: {
5360
tsSource: "client-ts",
@@ -58,10 +65,13 @@ const bccMiddle = new BCC_Middleware({
5865
mapSources: !parsedArgs.dev
5966
}
6067
})
68+
69+
// Clear the cache.
6170
if (parsedArgs.r) {
6271
await bccMiddle.bcc.clearAllCache()
6372
console.log("All Caches Cleared!")
6473
}
74+
// Pre-Compile the code.
6575
if (parsedArgs.c) {
6676
const preCompileList = [
6777
"dof8.ts",
@@ -75,22 +85,27 @@ if (parsedArgs.c) {
7585
await bccMiddle.bcc.compile(item);
7686
}
7787
}
88+
// Adds the cache source for SkyPack.
7889
bccMiddle.bcc.addCacheSource("SkyPack", "https://cdn.skypack.dev/");
79-
app.use( async (context: Context, next) => {
80-
await next();
81-
})
82-
app.use(bccMiddle.middleware())
90+
// Load the middleware.
91+
app.use(bccMiddle.middleware());
92+
// SkyPack Shim since it likes absolute paths with no domain.
8393
app.use(async (context: Context, next: () => Promise<void>) => {
94+
// Just make sure only SkyPack stuff is in the dir `/-/` :P
8495
if (context.request.url.pathname.startsWith("/-/")) {
8596
context.response.body = await bccMiddle.bcc.scriptCache(context.request.url.pathname.replace("/", ""), "SkyPack");
8697
context.response.type = "text/javascript";
8798
} else {
8899
await next();
89100
}
90101
})
102+
103+
// Router stuff.
104+
const router = new Router();
91105
app.use(router.routes());
92106
app.use(router.allowedMethods());
93107

108+
// This is for the actual HTML pages.
94109
router.get("/renderer.html", async (context: Context) => {
95110
console.log("Hit renderer.")
96111
context.response.body = await Deno.readTextFile(`${Deno.cwd()}/static/renderer.html`);
@@ -103,13 +118,17 @@ router.get("/renderer.html", async (context: Context) => {
103118
console.log("Hit Index.")
104119
context.response.body = await Deno.readTextFile(`${Deno.cwd()}/static/index.html`);
105120
context.response.type = "text/html";
106-
}).get("/test.mp4", async (context: Context) => {
121+
});
122+
123+
// This is a test file.
124+
router.get("/test.mp4", async (context: Context) => {
107125
console.log("Hit Index.");
108126
const imageBuf = await Deno.readFile(`${Deno.cwd()}/static/first-1-min.mp4`);
109127
context.response.body = imageBuf;
110128
context.response.type = "text/html";
111129
});
112130

131+
// These are test animations. They will be moved to client code in the WebRTC update.
113132
router.get("/trigger/song10", (context: Context) => {
114133
AniTests.animationLoop(rendererSocket, AniTests.song10Gen);
115134
context.response.body = "running..."

0 commit comments

Comments
 (0)