| import express from "express"; |
| import path from "path"; |
| import { fileURLToPath } from "url"; |
| import { derive } from "./derive-lib.mjs"; |
|
|
| const __filename = fileURLToPath(import.meta.url); |
| const __dirname = path.dirname(__filename); |
|
|
| const app = express(); |
| app.disable("x-powered-by"); |
|
|
| app.use(express.json({ limit: "1mb" })); |
|
|
| |
| app.use("/static", express.static(path.join(__dirname, "static"))); |
|
|
| app.get("/", (_req, res) => { |
| res.sendFile(path.join(__dirname, "static", "index.html")); |
| }); |
|
|
| app.post("/api/derive", (req, res) => { |
| try { |
| const { scheme = "tupa", text = "", options = undefined } = req.body || {}; |
| res.json(derive({ scheme, text, options })); |
| } catch (e) { |
| res.status(400).send(e?.message ? String(e.message) : String(e)); |
| } |
| }); |
|
|
| const port = Number.parseInt(process.env.PORT || "8000", 10); |
| app.listen(port, () => { |
| |
| console.log(`Server listening on http://127.0.0.1:${port}`); |
| }); |
|
|