import express from "express";
import path from "path";

const PORT = process.env.PORT ? +process.env.PORT : 3500;

const app = express();
const server = app.listen(PORT, () =>
  console.log(`[Express] Listening on port ${PORT}`)
);

app.use("/", require("./api"));
app.use("*", express.static(path.resolve(__dirname, "..", "build")));

// error handling endware
app.use((err: any, req: any, res: any, next: any) => {
  console.error(err);
  res.status(err.status || 500).send(err.message || "Internal server error.");
  next();
});
