Switch main's route handlers to be static functions (#2712)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-05-12 08:08:42 -04:00
1 parent b373411a16
commit f4ff28e51c
11 files changed
+173 -196

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
import http from "http";
export function respondJson(res: http.ServerResponse, content: any, status = 200) {
respond(res, JSON.stringify(content), "application/json", status);
}
export function respondText(res: http.ServerResponse, content: string, status = 200) {
respond(res, content, "text/plain", status);
}
export function respond(res: http.ServerResponse, content: string, contentType: string, status = 200) {
res.setHeader("Content-Type", contentType);
res.statusCode = status;
res.end(content);
}