aboutsummaryrefslogtreecommitdiffstats
path: root/claude-julia/server.ts
diff options
context:
space:
mode:
authorScott Lawrence <scott+git@ineffectivetheory.com>2025-03-19 21:23:32 -0600
committerScott Lawrence <scott+git@ineffectivetheory.com>2025-03-19 21:23:32 -0600
commitbab7929215b3d5a1d66b43ee5b03ad767aa32374 (patch)
tree0d945d2ffb6ed49ad8e6992d6ea8a0402bb47782 /claude-julia/server.ts
downloadmini-bab7929215b3d5a1d66b43ee5b03ad767aa32374.tar.gz
mini-bab7929215b3d5a1d66b43ee5b03ad767aa32374.tar.bz2
mini-bab7929215b3d5a1d66b43ee5b03ad767aa32374.zip
Initial commit
Diffstat (limited to 'claude-julia/server.ts')
-rw-r--r--claude-julia/server.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/claude-julia/server.ts b/claude-julia/server.ts
new file mode 100644
index 0000000..09c3fb4
--- /dev/null
+++ b/claude-julia/server.ts
@@ -0,0 +1,64 @@
+import * as http from "http";
+import * as fs from "fs";
+
+import { query } from "./query";
+
+const hostname = "localhost";
+const port = 3000;
+
+function readFiles(l: Array<string>) {
+ let m = new Map<string,ArrayBuffer>();
+ for (const fn of l) {
+ m.set(fn, fs.readFileSync(fn));
+ }
+ return m;
+}
+
+const files: Map<string,ArrayBuffer> = readFiles(["index.html", "style.css", "client.js"]);
+
+async function readBody(req: http.IncomingMessage): Promise<string> {
+ return new Promise((resolve, reject) => {
+ let chunks: Buffer[] = [];
+ req.on('data', (chunk: Buffer) => {
+ chunks.push(chunk);
+ });
+ req.on('end', () => {
+ resolve(Buffer.concat(chunks).toString());
+ });
+ });
+}
+
+const server = http.createServer(async (req: http.IncomingMessage,res) => {
+ switch (req.url) {
+ case "/":
+ res.statusCode = 200;
+ res.end(files.get("index.html"));
+ break;
+ case "/style.css":
+ res.statusCode = 200;
+ res.end(files.get("style.css"));
+ break;
+ case "/client.js":
+ res.statusCode = 200;
+ res.end(files.get("client.js"));
+ break;
+ case "/query":
+ if (req.method !== 'POST') {
+ res.statusCode = 405;
+ res.end('Must use POST');
+ return;
+ }
+ res.statusCode = 200;
+ let body = await readBody(req);
+ let response = await query(body);
+ res.end(response);
+ break;
+ default:
+ res.statusCode = 404;
+ res.setHeader('Content-Type', 'text/html');
+ res.end('Not found!');
+ }
+});
+
+server.listen(port, hostname, () => {});
+