-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.js
27 lines (25 loc) · 926 Bytes
/
simple.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
import { serve } from "https://deno.land/std@0.153.0/http/server.ts";
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") { // boxになければ問い合わせがある
const n = 0;
const res = new Uint8Array([0, 0, n >> 8, n]);
//const res = new TextEncoder().encode("IchigoJam"); // 先頭4byteのみ受信可能
return new Response(res);
}
return new Response("ok");
} catch (e) {
console.log(e);
}
}, { hostname, port });