Skip to content

Instantly share code, notes, and snippets.

@pepesenaris
Created July 19, 2018 18:03
Show Gist options
  • Select an option

  • Save pepesenaris/11dde803640d949793d280c336c9d6f2 to your computer and use it in GitHub Desktop.

Select an option

Save pepesenaris/11dde803640d949793d280c336c9d6f2 to your computer and use it in GitHub Desktop.
Express boilerplate to send email
// 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