chanded api names
This commit is contained in:
3629
public/data.json
3629
public/data.json
File diff suppressed because one or more lines are too long
10
server.js
10
server.js
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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; });
|
||||
|
||||
Reference in New Issue
Block a user