Vercel Node.js host 404: NOT_FOUND

73 Views Asked by At

I want to host my node.js in Vercel but when I deployed it I got a 404 error I don't really know what to do. If this will be helpfull that's my server.js script:

// server.js

const express = require('express');
const setupVulcan = require('./vulcanApiExample');

const app = express();

const startServer = async () => {
  app.use(express.json());

  app.post('/api/login', async (req, res) => {
             //example code
    } catch (error) {
      console.error('Error logging in:', error);
      res.status(500).json({ success: false, error: 'Internal Server Error' });
    }
  });

  const PORT = process.env.PORT || 5000;

  app.listen(PORT, () => {
    console.log(`Server is running on http://localhost:${PORT}`);
  });
};

startServer().catch((error) => {
  console.error('Error starting the server:', error);
});

and vercel.js:

{
    "rewrites": [{ "source": "/api/(.*)", "destination": "/api" }]
  }
0

There are 0 best solutions below