Hi, I have been trying to run a server app on Vercel, following the template (GitHub - vercel-support/express-vercel). This is the repo (GitHub - i-atanasov/osogovo-run-api), and this is the project domain (https://osogovo-run-api.vercel.app/). I have tryed everything with the cors policies, the vercel.json config and guidelines like these (Express 101: Everything about deploying your Express app on Vercel) or these (Debugging 404 Errors). Still I am receiving cors errors when I try to reach it from the client locally and ot prod, and it only returns 404 when I hit it directly. Could you help me with what I am still missing?
Here is the vercel.json:
{
ārewritesā: [{ āsourceā: ā/(.*)ā, ādestinationā: ā/apiā }]
}
Here is the api.index.ts:
import express from 'express'; import cors from 'cors'; import 'dotenv/config'; import { signUpHandler } from '../handlers/signUpHandler'; const app = express(); app.use(cors({origin: ["http://localhost:3000", "https://osogovorun.vercel.app/", "https://osogovo.run"]})); // Allow CORS from specific origins app.use(express.json()); app.get("/test-cors-get", function (req, res) { res.status(200).json({ success: true }); }); app.post("/test-cors-post", function (req, res) { res.status(200).json({ success: true }); }); app.get('/', (req, res) => { res.status(200).send('Welcome to the Osogovo Run API'); }); app.post('/register', signUpHandler.post); // Start the server app.listen(process.env.PORT || 4000, () => { console.log(`Server is running on port ${process.env.PORT || 4000}`); });
