Issue with Express server

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}`);
});

There’s another community post with 404 debugging tips that might be helpful. Please give these solutions a try and let us know how it goes.

A human should be around soon to offer more advice. But you can also get helpful information quickly by asking v0.

If you’re having trouble deploying an Express app, this guide can help.

You can also ask v0 for suggestions tailored to your own project setup.

Hey @i-atanasov. I checked the logs for the most recent deployment. Looks like there’s a typo in the config filename. If you change it from versel.json to vercel.json your rewrites will start working

1 Like

Thanks, it looks like this did the job.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.