Created
July 10, 2020 06:36
-
-
Save mcjcloud/cd3c547f2b1e27711195c383ae9631ff to your computer and use it in GitHub Desktop.
Asterisk Medium Article: backend entrypoint
This file contains 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 cors from "cors" | |
import express from "express" | |
import { todoRouter } from "./routes/todo" | |
// create a new express app | |
// this will be used to add all routes and request handlers | |
const app = express() | |
// allow express to accept application/json requests | |
app.use(express.json()) | |
// allow the backend to be accessed from your frontend | |
app.use(cors()) | |
// add the todo route | |
// all routes specified by todoRouter will be hit with /todo/{route} | |
app.use("/todo", todoRouter) | |
// start the app | |
app.listen(process.env.PORT || 8080, () => console.log("Server started.")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment