Skip to content

Commit dae51d0

Browse files
committed
feat: add custom builder ui
1 parent 1807534 commit dae51d0

File tree

7 files changed

+318
-20
lines changed

7 files changed

+318
-20
lines changed

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
},
8383
"serve": {
8484
"description": "Serve website locally",
85-
"command": "deno serve --allow-read --allow-env --allow-net --allow-run --allow-write=/tmp --port=4649 --location=http://localhost:4649 www/serve.ts"
85+
"command": "deno serve --allow-read --allow-env --allow-net --allow-run --allow-write=/tmp --allow-sys=osRelease --port=4649 --location=http://localhost:4649 www/serve.ts"
8686
},
8787
// Miscellaneous tasks
8888
"repo:fill-scopes": {

deno.lock

Lines changed: 115 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/api/build.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env DENO_DIR=/tmp deno run --version=v2.1.2 --allow-env --allow-read --allow-sys=osRelease
2+
// Imports
3+
import { STATUS_CODE as Status, STATUS_TEXT as StatusText } from "@std/http"
4+
import { banner as _banner, js, meta } from "@www/tools.ts"
5+
6+
/** API: Minify css */
7+
export default async function (request: Request) {
8+
if (request.method !== "POST") {
9+
return new Response(StatusText[Status.MethodNotAllowed], { status: Status.MethodNotAllowed })
10+
}
11+
if (new URL(`https://${request.headers.get("Host")}`).hostname !== new URL(`https://${Deno.env.get("ALLOWED_HOST") || "localhost"}`).hostname) {
12+
return new Response("Custom builds may not be linked directly", { status: Status.Forbidden })
13+
}
14+
try {
15+
const options = await request.json()
16+
const banner = _banner.replace(`${meta.name}${meta.version}\n`, `${meta.name}${meta.version} — Custom build (${new Date().toDateString()})\n`)
17+
const bundled = await js("@mizu/render/client", { format: "iife", banner, minify: options.minify ? "terser" : false })
18+
return new Response(bundled, { headers: { "Content-Type": "application/javascript; charset=utf-8" } })
19+
} catch (error) {
20+
return new Response(error.message, { status: Status.InternalServerError })
21+
}
22+
}

0 commit comments

Comments
 (0)