import { Application, Router } from "oak"
import { operation } from "../utilities/operation.ts"
import { join } from "std/path/join.ts"
const PORT = 8000
const ROUTER = new Router()
ROUTER.get("/", (ctx) => {
ctx.response.type = "text/html"
ctx.response.body = Deno.readTextFileSync("./src/pages/index.html")
})
ROUTER.post("/", async (ctx) => {
const FORM_DATA = await ctx.request.body.formData()
try {
await operation({
"font-family": (FORM_DATA.get("font-family") ?? "") as string,
"css-content": (FORM_DATA.get("custom-css") ?? "") as string,
"restore-backup": FORM_DATA.has("restore-backup") as boolean,
})
ctx.response.redirect("/")
} catch (error: unknown) {
if (!(error instanceof Error)) throw error
ctx.response.body = error.message
}
})
const APP = new Application()
APP.use(ROUTER.routes())
APP.use(async (ctx, next) => {
try {
await ctx.send({
root: join(Deno.cwd(), "/src/static"),
})
} catch {
next()
}
})
console.log("Open the URL in your browser:")
console.log(`http://localhost:${PORT}`)
await APP.listen({ port: PORT })
import { Application, Router } from "oak"
import { operation } from "../utilities/operation.ts"
import { join } from "std/path/join.ts"
const PORT = 8000
const ROUTER = new Router()
ROUTER.get("/", (ctx) => {
ctx.response.type = "text/html"
ctx.response.body = Deno.readTextFileSync("./src/pages/index.html")
})
ROUTER.post("/", async (ctx) => {
const FORM_DATA = await ctx.request.body.formData()
try {
await operation({
"font-family": (FORM_DATA.get("font-family") ?? "") as string,
"css-content": (FORM_DATA.get("custom-css") ?? "") as string,
"restore-backup": FORM_DATA.has("restore-backup") as boolean,
})
ctx.response.redirect("/")
} catch (error: unknown) {
if (!(error instanceof Error)) throw error
ctx.response.body = error.message
}
})
const APP = new Application()
APP.use(ROUTER.routes())
APP.use(async (ctx, next) => {
try {
await ctx.send({
root: join(Deno.cwd(), "/src/static"),
})
} catch {
next()
}
})
console.log("Open the URL in your browser:")
console.log(`http://localhost:${PORT}`)
await APP.listen({ port: PORT })