During implementation verification, I discovered that backend/src/index.ts (the main entry point) was NOT using the backend/src/app.ts file that contains all the route configurations, including our contract registry endpoint.
Before Fix:
backend/src/index.ts- Minimal Express setup with only/authand/healthroutesbackend/src/app.ts- Complete app with all routes including/api/contracts- Result: Contract registry endpoint was NOT accessible because app.ts wasn't being used
After Fix:
- Updated
backend/src/index.tsto import and use the completeapp.ts - Now all routes are properly registered including:
/api/contracts- Contract registry (our implementation)/api/employees- Employee management/api/payments- Payment processing/api/search- Search functionality- And all other routes
// OLD (backend/src/index.ts)
import express from "express";
import cors from "cors";
import helmet from "helmet";
import dotenv from "dotenv";
import passport from "./config/passport.js";
import authRoutes from "./routes/authRoutes.js";
dotenv.config();
const app = express();
const PORT = process.env.PORT || 4000;
app.use(helmet());
app.use(cors());
app.use(express.json());
app.use(passport.initialize());
// Routes
app.use("/auth", authRoutes);
app.get("/health", (req, res) => {
res.json({ status: "ok" });
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});// NEW (backend/src/index.ts)
import dotenv from "dotenv";
import app from "./app.js";
import logger from "./utils/logger.js";
import config from "./config/index.js";
dotenv.config();
const PORT = config.port || process.env.PORT || 3000;
app.listen(PORT, () => {
logger.info(`Server running on port ${PORT}`);
logger.info(`Environment: ${config.nodeEnv}`);
logger.info(`Health check: http://localhost:${PORT}/health`);
logger.info(`Contract registry: http://localhost:${PORT}/api/contracts`);
});❌ /api/contracts endpoint would return 404
❌ Most API routes would not work
❌ Only /auth and /health endpoints available
✅ /api/contracts endpoint fully functional
✅ All API routes properly registered
✅ Complete application functionality restored
To verify the fix works:
-
Start the backend:
cd backend npm run dev -
You should see in the logs:
Server running on port 3000 Environment: development Health check: http://localhost:3000/health Contract registry: http://localhost:3000/api/contracts -
Test the endpoint:
curl http://localhost:3000/api/contracts
-
Should return JSON with contract data (not 404)
The codebase appears to have two different app initialization patterns:
- A minimal
index.ts(possibly from an earlier version) - A complete
app.ts(current architecture)
The index.ts was never updated to use the complete app.ts, so routes defined in app.ts were never registered.
Always verify that:
- The entry point (package.json "main" field) is correct
- The entry point file uses the correct app configuration
- Test the actual running server, not just the code files
This is why the test script (test-contract-endpoint.sh) is important - it would have caught this issue immediately!