This commit is contained in:
728
2023-01-24 13:11:14 +08:00
parent 4e61fb7691
commit d3c82e9277
4 changed files with 64 additions and 0 deletions

View File

@ -5,4 +5,5 @@ rm -rf ui
cd ismism.ts
deno bundle src/serve.ts ../cli/serve.js
deno bundle cli/dbreset.ts ../cli/dbreset.js

View File

@ -0,0 +1,8 @@
import { DocR } from "../db.ts"
export async function query<T>(
f: string,
p: URLSearchParams,
): DocR<T> {
return null
}

48
ismism.ts/src/serve.ts Normal file
View File

@ -0,0 +1,48 @@
import { serve } from "https://deno.land/std@0.173.0/http/server.ts"
import { jwk_load } from "./ontic/jwt.ts"
import { utc_short } from "./ontic/utc.ts"
import { query } from "./praxic/query.ts"
let etag = `W/"${Date.now()}"`
function log(
utc: number,
msg: string,
status?: number,
) {
console.log(`${utc_short(utc)} - ${msg} - ${status ?? ""} - ${etag}`)
}
async function route(
req: Request
): Promise<Response> {
const url = new URL(req.url)
const [_, r, f] = url.pathname.split("/")
const t = Date.now()
switch (r) {
case "quit": {
log(t, "quit")
Deno.exit(); break
} case "update": {
etag = `W/"${t}"`
log(t, "etag updated")
return new Response(null, { status: 200, headers: { etag } })
} case "q": {
if (req.headers.get("if-none-match")?.includes(etag)) {
log(t, `${f}${url.search}`, 304)
return new Response(null, { status: 304, headers: { etag } })
}
log(t, `${f}${url.search}`, 200)
return new Response(
JSON.stringify(await query(f, url.searchParams)), {
status: 200,
headers: { etag }
})
}
}
return new Response(null, { status: 400 })
}
await jwk_load()
serve(route, { port: 728 })

7
ismism.ts/tst/query.http Normal file
View File

@ -0,0 +1,7 @@
GET http://localhost:728/quit
###
GET http://localhost:728/update HTTP/1.1
###
GET http://localhost:728/q HTTP/1.1