From be369c920e63db615d42be6e5cf5683727176874 Mon Sep 17 00:00:00 2001 From: Bibiing Date: Wed, 18 Dec 2024 08:26:05 +0700 Subject: [PATCH] backend(24) --- server.js | 19 +++++-------------- vercel.json | 29 ++--------------------------- 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/server.js b/server.js index 91b3196..3cba14a 100644 --- a/server.js +++ b/server.js @@ -120,20 +120,11 @@ app.use("/images", imageRoutes); const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -if (process.env.NODE_ENV === "production") { - const distPath = path.join(__dirname, "dist"); - console.log(`Serving static files from: ${distPath}`); - console.log("Current directory:", __dirname); - console.log("Environment:", process.env.NODE_ENV); - console.log("Dist path:", path.join(__dirname, "dist")); - // Serve static files - app.use(express.static(distPath)); - - // Catch-all route for SPA - app.get("*", (req, res) => { - res.sendFile(path.join(distPath, "index.html")); - }); -} +// Serve static files and handle SPA routing +app.use(express.static(path.join(__dirname, "dist"))); +app.get("*", (req, res) => { + res.sendFile(path.join(__dirname, "dist", "index.html")); +}); // Global Error Handler app.use((err, req, res, next) => { diff --git a/vercel.json b/vercel.json index 69ce77e..a8c7f05 100644 --- a/vercel.json +++ b/vercel.json @@ -1,35 +1,10 @@ { "version": 2, - "builds": [ - { - "src": "dist/index.html", - "use": "@vercel/static" - }, - { - "src": "server.js", - "use": "@vercel/node" - } - ], + "builds": [{ "src": "server.js", "use": "@vercel/node" }], "routes": [ - { - "src": "/api/(.*)", - "dest": "server.js" - }, - { - "src": "/auth/(.*)", - "dest": "server.js" - }, - { - "src": "/upload/(.*)", - "dest": "server.js" - }, - { - "src": "/images/(.*)", - "dest": "server.js" - }, { "src": "/(.*)", - "dest": "dist/index.html" + "dest": "server.js" } ] }