server.js 681 Bytes
const express = require("express");
const cors = require("cors");

const loginRouter = require("./routers/Login");
const dbRouter = require("./routers/DB");
const path = require("path");

const app = express();

app.use(
  cors({
    origin: `http://${process.env.REACT_APP_IP}:3000`,
    credentials: true,
  })
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.use("/login", loginRouter);
app.use("/db", dbRouter);

app.use(express.static(path.join(__dirname, "../build")));
app.get("*", function (req, res) {
  res.sendFile(path.join(__dirname, "../build/index.html"));
});

app.listen(3001, function () {
  console.log("listening on 3001");
});