index.ts 533 B

12345678910111213141516171819
  1. import express from "express";
  2. import path from "path";
  3. const PORT = process.env.PORT ? +process.env.PORT : 3500;
  4. const app = express();
  5. const server = app.listen(PORT, () =>
  6. console.log(`[Express] Listening on port ${PORT}`)
  7. );
  8. app.use("/", require("./api"));
  9. app.use("*", express.static(path.resolve(__dirname, "..", "build")));
  10. // error handling endware
  11. app.use((err: any, req: any, res: any, next: any) => {
  12. console.error(err);
  13. res.status(err.status || 500).send(err.message || "Internal server error.");
  14. next();
  15. });