Skip to content

Commit

Permalink
👨🏾‍🍳 Dev sunucuyu kitaplıktan kullan
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Nov 27, 2023
1 parent 8d401ee commit a2ff1aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib
Submodule lib updated 5 files
+24 −4 util/birimler.js
+117 −0 util/latex.css
+305 −0 util/latex.js
+41 −0 util/sunucu.js
+111 −0 util/svg.cjs
48 changes: 6 additions & 42 deletions sunucu/dev.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import express from "express";
import { readFileSync } from "fs";
import { parse } from "toml";
import { createServer } from "vite";
import { sayfaOku } from "../lib/util/birimler.js";
import { devSunucu } from "../lib/util/sunucu.js";

/** @const {Object<string, string>} */
const SAYFALAR = {
const config = parse(readFileSync('sunucu/dev.toml'));
console.log(`Ana sayfaya şu adreste çalışıyor: http://localhost:${config.port}`)

devSunucu(config.port, {
"/": { ad: "ana/sayfa.html", dil: "tr" },
"/al": { ad: "al/sayfa.html", dil: "tr" },
"/mint": { ad: "al/sayfa.html", dil: "en" },
Expand All @@ -15,40 +15,4 @@ const SAYFALAR = {
"/vote": { ad: "oyla/sayfa.html", dil: "en" },
"/iptal": { ad: "iptal/sayfa.html", dil: "tr" },
"/revoke": { ad: "iptal/sayfa.html", dil: "en" },
};

createServer({
server: { middlewareMode: true },
appType: 'custom'
}).then((vite) => {
const app = express()
app.get("/*.svg", (req, res) => {
const sayfaAdı = decodeURIComponent(req.path.slice(1));
const svg = sayfaOku(sayfaAdı, { dil: "en", dev: true })
res.status(200).set({ "content-type": "image/svg+xml" }).end(svg);
})
app.use(vite.middlewares)
app.use(Object.keys(SAYFALAR), (req, res, next) => {
if (!(req.path in SAYFALAR)) {
res.status(200).end(); // Dev sunucuda hata vermemeye çalış
} else {
const { ad, dil } = SAYFALAR[req.path]
/** @const {string} */
const sayfa = sayfaOku(ad, {
dil: "tr" in req.query ? "tr" : "en" in req.query ? "en" : dil,
dev: true
});
vite.transformIndexHtml(req.path, sayfa).then((sayfa) => {
res.status(200)
.set({ 'Content-type': 'text/html;charset=utf-8' })
.end(sayfa);
}).catch((e) => {
vite.ssrFixStacktrace(e)
next(e)
})
}
})
const config = parse(readFileSync('sunucu/dev.toml'));
console.log(`Ana sayfaya şu adreste çalışıyor: http://localhost:${config.port}`)
app.listen(config.port);
})
});

0 comments on commit a2ff1aa

Please sign in to comment.