chanded api names

This commit is contained in:
Jelaletdin12
2026-03-27 23:01:33 +05:00
parent 7dc9a5fbc7
commit 7c75205077
5 changed files with 10 additions and 3637 deletions

File diff suppressed because one or more lines are too long

View File

@@ -3,11 +3,11 @@ import fs from "fs";
import path from "path"; import path from "path";
const app = express(); const app = express();
const port = 3000; const port = 4173;
// API endpointleri // API endpointleri
app.post("/api/data", express.json(), (req, res) => { app.post("/frontend-api/data", express.json(), (req, res) => {
fs.writeFile(path.join(process.cwd(), "public", "data.json"), JSON.stringify(req.body, null, 2), (err) => { fs.writeFile(path.join(process.cwd(), "dist", "data.json"), JSON.stringify(req.body, null, 2), (err) => {
if (err) { if (err) {
res.status(500).send(err.message); res.status(500).send(err.message);
} else { } else {
@@ -16,8 +16,8 @@ app.post("/api/data", express.json(), (req, res) => {
}); });
}); });
app.get("/api/data", (req, res) => { app.get("/frontend-api/data", (req, res) => {
fs.readFile(path.join(process.cwd(), "public", "data.json"), "utf-8", (err, data) => { fs.readFile(path.join(process.cwd(), "dist", "data.json"), "utf-8", (err, data) => {
if (err) { if (err) {
res.status(500).send(err.message); res.status(500).send(err.message);
} else { } else {

View File

@@ -106,7 +106,7 @@ export default function CarConfigurator() {
// Load data.json — served from /public/data.json, readable by all users // Load data.json — served from /public/data.json, readable by all users
useEffect(() => { useEffect(() => {
fetch("/api/data") fetch("/frontend-api/data")
.then((r) => r.json()) .then((r) => r.json())
.then((data) => { .then((data) => {
setAppData(data); setAppData(data);

View File

@@ -66,7 +66,7 @@ function AdminPanel({ onLogout }) {
// Load data.json from /public // Load data.json from /public
useEffect(() => { useEffect(() => {
fetch("api/data") fetch("/frontend-api/data")
.then((r) => r.json()) .then((r) => r.json())
.then((d) => { .then((d) => {
setData(d); setData(d);
@@ -159,7 +159,7 @@ function AdminPanel({ onLogout }) {
// ── Save = download updated data.json ────────────────────── // ── Save = download updated data.json ──────────────────────
// Since there's no backend, admin downloads the JSON and replaces public/data.json // Since there's no backend, admin downloads the JSON and replaces public/data.json
async function handleSave() { async function handleSave() {
const res = await fetch("/api/data", { const res = await fetch("/frontend-api/data", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify(data), body: JSON.stringify(data),

View File

@@ -9,7 +9,7 @@ export default defineConfig({
{ {
name: "data-api", name: "data-api",
configureServer(server) { configureServer(server) {
server.middlewares.use("/api/data", (req, res, next) => { server.middlewares.use("/frontend-api/data", (req, res, next) => {
if (req.method === "POST") { if (req.method === "POST") {
let body = ""; let body = "";
req.on("data", (chunk) => { body += chunk; }); req.on("data", (chunk) => { body += chunk; });