Just moving HTTP code around.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4303 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-05-17 18:35:58 +00:00
parent e237c7ea1d
commit 478e96fc5f

View File

@ -811,6 +811,16 @@ function enableStats(process, enabled) {
}
}
function stringResponse(response, data) {
let bytes = utf8Encode(data);
response.writeHead(200, {
"Content-Type": "application/json; charset=utf-8",
"Content-Length": bytes.byteLength.toString(),
"Access-Control-Allow-Origin": "*",
});
return response.end(bytes);
}
loadSettings().then(function() {
httpd.all("/login", auth.handler);
httpd.all("", function(request, response) {
@ -824,8 +834,6 @@ loadSettings().then(function() {
return blobHandler(request, response, match[1], match[2]);
} else if (match = /^\/static\/lit\/([\.\w-/]*)$/.exec(request.uri)) {
return staticDirectoryHandler(request, response, 'deps/lit/', match[1]);
} else if (match = /^\/static(\/.*)/.exec(request.uri)) {
return staticFileHandler(request, response, null, match[1]);
} else if (match = /^\/codemirror\/([\.\w-/]*)$/.exec(request.uri)) {
return staticDirectoryHandler(request, response, 'deps/codemirror/', match[1]);
} else if (match = /^\/speedscope\/([\.\w-/]*)$/.exec(request.uri)) {
@ -834,34 +842,22 @@ loadSettings().then(function() {
return staticDirectoryHandler(request, response, 'deps/split/', match[1]);
} else if (match = /^\/smoothie\/([\.\w-/]*)$/.exec(request.uri)) {
return staticDirectoryHandler(request, response, 'deps/smoothie/', match[1]);
} else if (match = /^\/static(\/.*)/.exec(request.uri)) {
return staticFileHandler(request, response, null, match[1]);
} else if (request.uri == "/robots.txt") {
return staticFileHandler(request, response, null, request.uri);
} else if (match = /^(.*)(\/(?:save|delete)?)$/.exec(request.uri)) {
return blobHandler(request, response, match[1], match[2]);
} else if (match = /^\/trace$/.exec(request.uri)) {
let data = trace();
response.writeHead(200, {"Content-Type": "application/json; charset=utf-8", "Content-Length": data.length.toString()});
return response.end(data);
return stringResponse(response, trace());
} else if (match = /^\/disconnections$/.exec(request.uri)) {
let data = utf8Encode(JSON.stringify(disconnectionsDebug(), null, 2));
response.writeHead(200, {"Content-Type": "application/json; charset=utf-8", "Content-Length": data.byteLength.toString()});
return response.end(data);
return stringResponse(response, JSON.stringify(disconnectionsDebug(), null, 2));
} else if (match = /^\/debug$/.exec(request.uri)) {
let data = JSON.stringify(getDebug(), null, 2);
response.writeHead(200, {"Content-Type": "application/json; charset=utf-8", "Content-Length": data.length.toString()});
return response.end(data);
return stringResponse(response, JSON.stringify(getDebug(), null, 2));
} else if (match = /^\/hitches$/.exec(request.uri)) {
let data = JSON.stringify(getHitches(), null, 2);
response.writeHead(200, {"Content-Type": "application/json; charset=utf-8", "Content-Length": data.length.toString()});
return response.end(data);
return stringResponse(response, JSON.stringify(getHitches(), null, 2));
} else if (match = /^\/mem$/.exec(request.uri)) {
let data = JSON.stringify(getAllocations(), null, 2);
response.writeHead(200, {
"Content-Type": "application/json; charset=utf-8",
"Content-Length": data.length.toString(),
"Access-Control-Allow-Origin": "*",
});
return response.end(data);
} else if (request.uri == "/robots.txt") {
return blobHandler(request, response, null, request.uri);
return stringResponse(response, JSON.stringify(getAllocations(), null, 2));
} else if ((match = /^\/.well-known\/(.*)/.exec(request.uri)) && request.uri.indexOf("..") == -1) {
return wellKnownHandler(request, response, match[1]);
} else {