Files
mm.com.tm-frontend/server.js
2026-04-13 20:47:11 +05:00

42 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import express from "express";
import fs from "fs";
import path from "path";
const app = express();
const port = 4173;
// API endpointleri
app.post("/frontend-api/data", express.json({ limit: '20mb' }), (req, res) => {
fs.writeFile(path.join(process.cwd(), "dist", "data.json"), JSON.stringify(req.body, null, 2), (err) => {
if (err) {
res.status(500).send(err.message);
} else {
res.status(200).json({ ok: true });
}
});
});
app.get("/frontend-api/data", (req, res) => {
fs.readFile(path.join(process.cwd(), "dist", "data.json"), "utf-8", (err, data) => {
if (err) {
res.status(500).send(err.message);
} else {
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
res.setHeader("Pragma", "no-cache");
res.setHeader("Expires", "0");
res.setHeader("Content-Type", "application/json");
res.send(data);
}
});
});
// Statik dosyaları sun ve diğer tüm istekleri index.html'e yönlendir
app.use(express.static(path.join(process.cwd(), "dist")));
app.get(/^(?!\/api).*/, (req, res) => {
res.sendFile(path.join(process.cwd(), "dist", "index.html"));
});
app.listen(port, () => {
console.log(`Sunucu http://localhost:${port} adresinde çalışıyor`);
});