added car configurator
This commit is contained in:
41
server.js
Normal file
41
server.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import express from "express";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
// API endpointleri
|
||||
app.post("/api/data", express.json(), (req, res) => {
|
||||
fs.writeFile(path.join(process.cwd(), "public", "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("/api/data", (req, res) => {
|
||||
fs.readFile(path.join(process.cwd(), "public", "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`);
|
||||
});
|
||||
Reference in New Issue
Block a user