Created
July 19, 2018 18:03
-
-
Save pepesenaris/11dde803640d949793d280c336c9d6f2 to your computer and use it in GitHub Desktop.
Express boilerplate to send email
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
| // server/index.js | |
| app.use(express.json()); /* Parse json in request */ | |
| /* Priority serve any static files */ | |
| app.use(express.static(path.resolve(__dirname, "../react-ui/build"))); | |
| app.get("/api/send_email", function(req, res) { | |
| res.set("Content-Type", "application/json"); | |
| /* Send email here */ | |
| res.send('{"message":"Email sent."}'); | |
| }); | |
| /* All remaining requests return the React app, so it can handle routing. */ | |
| app.get("*", function(request, response) { | |
| response.sendFile(path.resolve(__dirname, "../react-ui/build", "index.html")); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment