-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwbgtserver.js
30 lines (27 loc) · 966 Bytes
/
wbgtserver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { serve } from "https://deno.land/std@0.153.0/http/server.ts";
import { getWBGT } from "https://code4fukui.github.io/wbgt-japan/getWBGT.js";
const STNUM_FUKUI = 57066;
const ipv6 = true;
const port = parseInt(Deno.args[1]) || 7001;
const hostname = ipv6 ? "[::]" : "localhost";
console.log(`http://${hostname}:${port}`);
serve(async (req) => {
try {
const { pathname } = new URL(req.url);
const iccid = req.headers.get("x-iccid");
const time = req.headers.get("x-time");
console.log(req, pathname, iccid, time);
if (req.method == "POST") {
const b = new Uint8Array(await req.arrayBuffer());
console.log(b);
} else if (req.method == "GET") {
const wbgt = await getWBGT(STNUM_FUKUI);
const n = Math.floor(wbgt.wbgt * 10);
const res = new Uint8Array([0, 0, n >> 8, n]);
return new Response(res);
}
return new Response("ok");
} catch (e) {
console.log(e);
}
}, { hostname, port });