Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const fileUpload = require("express-fileupload");
Expand Down Expand Up @@ -153,10 +154,36 @@ app.use("/api/v1/pipeline", pipelineRoutes);
// ──────────────────────────────────────────────────────────────────────────
// 8. Health check
// ──────────────────────────────────────────────────────────────────────────
app.get("/", (req, res) =>
// Moved off "/" so the root path is free to serve the React app below.
// Render's default health check accepts any 2xx response, so serving
// index.html at "/" satisfies it too — this route is for explicit pings.
app.get("/api/v1/health", (req, res) =>
res.json({ success: true, message: "StudyNotion server is running." })
);

// ──────────────────────────────────────────────────────────────────────────
// 8b. Serve the built React app (ui/build) — single-server deployment
// ──────────────────────────────────────────────────────────────────────────
const uiBuildPath = path.join(__dirname, "ui", "build");

if (!require("fs").existsSync(path.join(uiBuildPath, "index.html"))) {
console.warn(
"⚠ ui/build not found — run `npm run build` (or `npm install --prefix ui && npm run build --prefix ui`) first."
);
}

app.use(express.static(uiBuildPath));

// SPA fallback: anything not already matched above and not an /api/* route
// gets index.html so React Router can handle client-side routing. Must be
// registered LAST — after every API route — so API paths are never swallowed.
app.get("*", (req, res) => {
if (req.path.startsWith("/api/")) {
return res.status(404).json({ success: false, message: `Route '${req.path}' not found` });
}
res.sendFile(path.join(uiBuildPath, "index.html"));
});

// ──────────────────────────────────────────────────────────────────────────
// 9. Nightly ETL cron (runs at 01:00 UTC every day)
// ──────────────────────────────────────────────────────────────────────────
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"build": "npm install --prefix ui && npm run build --prefix ui",
"test": "cross-env NODE_ENV=test jest --runInBand --detectOpenHandles"
},
"keywords": [],
Expand Down
Loading
Loading