Created
September 16, 2018 12:00
-
-
Save Fabianopb/c638124a92055548fe113e61610ed678 to your computer and use it in GitHub Desktop.
app.ts for express-react-ts-ci Medium post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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