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";
const app = express();
const port = 3000;
const port = 4173;
// 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) => {
app.post("/frontend-api/data", express.json(), (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 {
@@ -16,8 +16,8 @@ app.post("/api/data", express.json(), (req, res) => {
});
});
app.get("/api/data", (req, res) => {
fs.readFile(path.join(process.cwd(), "public", "data.json"), "utf-8", (err, data) => {
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 {

View File

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

View File

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

View File

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