diff --git a/package.json b/package.json index c06ffc6..d597943 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,11 @@ "version": "0.0.0", "type": "module", "scripts": { - "start": "npm run build && node server.js", + "start": "node server.js", "build": "vite build", "dev": "concurrently \"npm run server\" \"npm run client\"", "server": "nodemon server.js", "client": "vite", - "lint": "eslint .", "preview": "vite preview" }, "dependencies": { diff --git a/server.js b/server.js index 7b1e29c..c19f841 100644 --- a/server.js +++ b/server.js @@ -40,7 +40,7 @@ app.use( imgSrc: ["'self'", "data:", "https:"], connectSrc: [ "'self'", - "https://chronocamm.vercel.app/", + "https://chronocamm.vercel.app", "https://vercel.live", ], }, @@ -62,7 +62,7 @@ const connectDB = async () => { // CORS Configuration app.use( cors({ - origin: "https://chronocamm.vercel.app/", + origin: "https://chronocamm.vercel.app", methods: ["GET", "POST", "PUT"], allowedHeaders: ["Content-Type", "Authorization"], credentials: true, @@ -140,3 +140,16 @@ process.on("SIGINT", async () => { process.exit(1); } }); + +// At the end of your server configuration, add: +if (process.env.NODE_ENV === "production") { + const path = require("path"); + + // Serve static files from frontend build + app.use(express.static(path.join(__dirname, "frontend/dist"))); + + // For any route not handled by API, serve the React app + app.get("*", (req, res) => { + res.sendFile(path.join(__dirname, "frontend/dist/index.html")); + }); +} diff --git a/vercel.json b/vercel.json index 574a1de..ef01755 100644 --- a/vercel.json +++ b/vercel.json @@ -1,6 +1,10 @@ { "version": 2, "builds": [ + { + "src": "frontend/dist", + "use": "@vercel/static" + }, { "src": "server.js", "use": "@vercel/node" @@ -8,11 +12,24 @@ ], "routes": [ { - "src": "/(.*)", + "src": "/api/(.*)", + "dest": "server.js" + }, + { + "src": "/auth/(.*)", + "dest": "server.js" + }, + { + "src": "/upload/(.*)", "dest": "server.js" + }, + { + "src": "/images/(.*)", + "dest": "server.js" + }, + { + "src": "/(.*)", + "dest": "frontend/dist/index.html" } - ], - "env": { - "NODE_ENV": "production" - } + ] } diff --git a/vite.config.js b/vite.config.js index cc8be4c..ae2f54b 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,9 +1,11 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; -// https://vite.dev/config/ export default defineConfig({ plugins: [react()], + build: { + outDir: "dist", + }, server: { proxy: { "/api": "http://localhost:8080",