wehub-cloud-tpl-web-function
3a8ee672fe
Co-authored-by: Cursor <cursoragent@cursor.com>
37 行
1.0 KiB
JavaScript
37 行
1.0 KiB
JavaScript
const http = require("http");
|
|
|
|
const PORT = process.env.PORT || process.env.WEHUB_PORT || "9000";
|
|
|
|
function json(res, status, body) {
|
|
res.statusCode = status;
|
|
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
res.end(JSON.stringify(body));
|
|
}
|
|
|
|
function bindings() {
|
|
return {
|
|
database: !!process.env.DATABASE_URL,
|
|
object_store: !!(process.env.S3_BUCKET && process.env.S3_CREDENTIALS_TOKEN && process.env.S3_CREDENTIALS_URL),
|
|
};
|
|
}
|
|
|
|
const server = http.createServer((req, res) => {
|
|
const url = (req.url || "/").split("?")[0];
|
|
if (req.method === "OPTIONS") {
|
|
res.statusCode = 204;
|
|
return res.end("");
|
|
}
|
|
if (req.method === "GET" && (url === "/health" || url === "/api/cloud/health")) {
|
|
return json(res, 200, {
|
|
ok: true,
|
|
service: "wehub-tpl-demo-web-function",
|
|
bindings: bindings(),
|
|
});
|
|
}
|
|
json(res, 200, { ok: true, routes: ["GET /health"] });
|
|
});
|
|
|
|
server.listen(Number(PORT), "0.0.0.0", () => {
|
|
console.log("wehub-tpl-demo-web-function listening on 0.0.0.0:" + PORT);
|
|
});
|