Download server.mjs from rtrm/test2: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/rtrm/test2/resolve/main/server.mjs
- Command line
-
hf download hf://spaces/rtrm/test2/server.mjs
-
curl -L -o server.mjs https://huggingface.co/spaces/rtrm/test2/resolve/main/server.mjs
1.03 kB
| import fs from "node:fs"; | |
| import http from "node:http"; | |
| import { fileURLToPath } from "node:url"; | |
| const port = Number(process.env.PORT ?? 7860); | |
| const publicPem = fs.readFileSync(fileURLToPath(new URL("./cert.pem", import.meta.url)), "utf8"); | |
| function json(res, statusCode, payload) { | |
| res.writeHead(statusCode, { "content-type": "application/json" }); | |
| res.end(JSON.stringify(payload, null, 2)); | |
| } | |
| function text(res, statusCode, payload, contentType = "text/plain") { | |
| res.writeHead(statusCode, { "content-type": contentType }); | |
| res.end(payload); | |
| } | |
| const server = http.createServer((req, res) => { | |
| const url = new URL(req.url ?? "/", "http://localhost"); | |
| if (req.method === "GET" && url.pathname === "/healthz") { | |
| json(res, 200, { ok: true }); | |
| return; | |
| } | |
| if (req.method === "GET" && url.pathname === "/cert.pem") { | |
| text(res, 200, publicPem, "application/x-pem-file"); | |
| return; | |
| } | |
| json(res, 404, { error: "not found" }); | |
| }); | |
| server.listen(port, "0.0.0.0", () => { | |
| console.log(`Listening on ${port}`); | |
| }); | |