import express from "express"; import path from "path"; require("dotenv").config(); const isDev = process.env.NODE_ENV !== "production" ? true : false; const app = express(); app.use(express.static(path.resolve(__dirname, "../", "build"))); app.use(express.static(path.resolve(__dirname, "../", "styleguide"))); app.set("port", process.env.PORT || 5000); const USERS = [ { id: 0, name: "Yomi Eluwande" }, { id: 1, name: "Nate Murray" }, { id: 2, name: "Sophia Shoemaker" } ]; app.get("/api/users", (req, res) => { res.send(USERS); }); app.get("/styleguide", function(req, res) { console.log("styleguide"); res.sendFile(path.resolve(__dirname, "../", "styleguide", "index.html")); }); app.get("/*", function(req, res) { res.sendFile(path.resolve(__dirname, "../", "build", "index.html")); }); app.use(function onError(err: any, req: any, res: any, next: any) { // The error id is attached to `res.sentry` to be returned // and optionally displayed to the user for support. res.statusCode = 500; res.end(`${res.sentry}\n`); }); app.listen(app.get("port"), () => { console.log("Node app is running on port", app.get("port")); });