Getting 'Not found' after deploying my react web application

57 Views Asked by At

I'm trying to deploy my React application on Vercel. After deployment I'm getting 'NOT FOUND' when i'm trying to visit the link. Screen shot attached.enter image description here

This is my index.js file code:

// express acts as a server
import express from "express";
import dotenv from "dotenv";
import Connection from "./database/db.js";
import DefaultData from "./default.js";
import router from "./routes/route.js";
import cors from "cors";
import bodyParser from "body-parser";
import { v4 as uuid} from "uuid";
import * as path from "path";
import { fileURLToPath } from "url";

// intializing

// creating server
// three arguments - port, callback function

const app = express();

dotenv.config();
app.use(cors());
app.use(bodyParser.json({ extended: true }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/", router);
const PORT = process.env.PORT || 8000;

Connection();

const __dirname = path.dirname(fileURLToPath(import.meta.url));

console.log(__dirname);

if (process.env.NODE_ENV === 'production') {
  

  app.use(express.static(path.join(__dirname, 'client', 'build')))

  app.get('/*', function (req, res) {
    res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'))
  });
}

app.listen(PORT, () =>
  console.log(`Server is running successfully on Port ${PORT}`)
);

// DefaultData();

I think this code is not able to resolve dirname. Please help me out..

0

There are 0 best solutions below