Skip to content

Commit

Permalink
🍦 Geliştirme sunucularını tekbiçime uydur
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Dec 17, 2023
1 parent 1a4f0cc commit f7f7a51
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions birimler/devSunucu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import express from "express";
import { readFileSync } from "fs";
import { parse } from "toml";
import { createServer } from "vite";
import { sayfaOku } from "./okuyucu.js";

/**
* @param {{
* port: number,
* hostname: (string|undefined),
* kök: (string|undefined),
* dizin: string,
* sayfalar: !Array<!Array<string>>
* }} seçenekler
*/
const çalıştır = (seçenekler) => createServer({
server: { middlewareMode: true },
appType: "custom"
Expand Down Expand Up @@ -57,6 +68,9 @@ const çalıştır = (seçenekler) => createServer({
app.listen(seçenekler.port);
});

if (process.argv[2] == "--çalıştır")
çalıştır(parse(readFileSync(process.argv[3])));

export {
çalıştır
};
47 changes: 47 additions & 0 deletions birimler/kanaryaSunucu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import express from "express";
import { readFileSync } from "fs";
import { parse } from "toml";

/**
* @param {{
* port: number,
* hostname: (string|undefined),
* kök: (string|undefined),
* dizin: string,
* sayfalar: !Array<!Array<string>>
* }} seçenekler
*/
const çalıştır = (seçenekler) => {
/** @const {string} */
const kök = (seçenekler.kök || "build") + "/";

/** @const {!Express} */
const app = express();

/** @const {!Object<string, string>} */
const harita = {};

harita["/"] = kök + seçenekler.dizin + "-tr.html";

for (const sayfa of seçenekler.sayfalar) {
harita["/" + sayfa[0]] = kök + sayfa[0] + "-tr.html";
harita["/" + sayfa[1]] = kök + sayfa[1] + "-en.html";
}

app.use(express.static(kök, {
redirect: false
}));
app.use(Object.keys(harita), (req, res) => {
res.status(200)
.set({ "content-type": "text/html;charset=utf-8" })
.end(readFileSync(harita[req.path]))
});

console.log(`Kanarya sunucu şu adreste çalışıyor: http://localhost:${seçenekler.port}`);
app.listen(seçenekler.port);
}

if (process.argv[2] == "--çalıştır")
çalıştır(parse(readFileSync(process.argv[3])));

export { çalıştır };

0 comments on commit f7f7a51

Please sign in to comment.