diff --git a/server.js b/server.js
index 3cba14a..91b3196 100644
--- a/server.js
+++ b/server.js
@@ -120,11 +120,20 @@ app.use("/images", imageRoutes);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
-// 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"));
-});
+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"));
+ });
+}
// Global Error Handler
app.use((err, req, res, next) => {
diff --git a/src/routes/Router.jsx b/src/routes/Router.jsx
index 399b53a..93181d8 100644
--- a/src/routes/Router.jsx
+++ b/src/routes/Router.jsx
@@ -6,7 +6,7 @@ import SignInPage from "../pages/SignInPage";
import ErrorPage from "../pages/ErrorPage";
import RouterErrorBoundary from "./RouterErrorBoundary";
import VerifyEmail from "../components/SignUp/VeryfyEmail";
-import ProfilePage from '../pages/ProfilePage';
+import ProfilePage from "../pages/ProfilePage";
import LoginSuccess from "../components/loginsuccess";
const routes = [
@@ -28,28 +28,33 @@ const routes = [
},
{
path: "/verify-email",
- element: ,
+ element: ,
},
{
path: "*",
element: ,
},
{
- path: '/Profile',
+ path: "/Profile",
element: ,
},
{
- path: '/login-success',
+ path: "/login-success",
element: ,
},
];
-const router = createBrowserRouter([
- {
- element: ,
- children: routes,
- },
-]);
+const router = createBrowserRouter(
+ [
+ {
+ element: ,
+ children: routes,
+ },
+ ],
+ {
+ basename: "/",
+ }
+);
const Routes = () => ;
diff --git a/vercel.json b/vercel.json
index a8c7f05..3f48d2c 100644
--- a/vercel.json
+++ b/vercel.json
@@ -1,10 +1,46 @@
{
"version": 2,
- "builds": [{ "src": "server.js", "use": "@vercel/node" }],
+ "builds": [
+ {
+ "src": "dist/index.html",
+ "use": "@vercel/static"
+ },
+ {
+ "src": "server.js",
+ "use": "@vercel/node"
+ }
+ ],
"routes": [
{
- "src": "/(.*)",
+ "src": "/api/(.*)",
+ "dest": "server.js"
+ },
+ {
+ "src": "/auth/(.*)",
+ "dest": "server.js"
+ },
+ {
+ "src": "/upload/(.*)",
+ "dest": "server.js"
+ },
+ {
+ "src": "/images/(.*)",
"dest": "server.js"
+ },
+ {
+ "src": "/(.*)",
+ "headers": {
+ "Cache-Control": "no-store, no-cache, must-revalidate, proxy-revalidate",
+ "Pragma": "no-cache",
+ "Expires": "0"
+ },
+ "dest": "/index.html"
+ }
+ ],
+ "rewrites": [
+ {
+ "source": "/(.*)",
+ "destination": "/index.html"
}
]
}
diff --git a/vite.config.js b/vite.config.js
index 2b0f979..ae2f54b 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -8,10 +8,10 @@ export default defineConfig({
},
server: {
proxy: {
- "/api": "https://chronocamm.vercel.app",
- "/auth": "https://chronocamm.vercel.app",
- "/upload": "https://chronocamm.vercel.app",
- "/images": "https://chronocamm.vercel.app",
+ "/api": "http://localhost:8080",
+ "/auth": "http://localhost:8080",
+ "/upload": "http://localhost:8080",
+ "/images": "http://localhost:8080",
},
},
});