Skip to content

Instantly share code, notes, and snippets.

@Fabianopb
Created September 16, 2018 12:00
Show Gist options
  • Save Fabianopb/c638124a92055548fe113e61610ed678 to your computer and use it in GitHub Desktop.
Save Fabianopb/c638124a92055548fe113e61610ed678 to your computer and use it in GitHub Desktop.
app.ts for express-react-ts-ci Medium post
import * as dotenv from "dotenv";
import * as express from "express";
import * as path from "path";
// Put dotenv in use before importing controllers
dotenv.config();
// Import controllers
import itemsController from "./items/items.controller";
import usersController from "./users/users.controller";
// Create the express application
const app = express();
// Assign controllers to routes
app.use("/api/items", itemsController);
app.use("/api/users", usersController);
// Declare the path to frontend's static assets
app.use(express.static(path.resolve("..", "frontend", "build")));
// Intercept requests to return the frontend's static entry point
app.get("*", (request, response) => {
response.sendFile(path.resolve("..", "frontend", "build", "index.html"));
});
export default app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment