Skip to content

Instantly share code, notes, and snippets.

@incorelabs
Last active January 14, 2018 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incorelabs/638be1473e2457e330d7efbc0e6d97ad to your computer and use it in GitHub Desktop.
Save incorelabs/638be1473e2457e330d7efbc0e6d97ad to your computer and use it in GitHub Desktop.
FDWorkshop - Heroku API Server JS file
const express = require("express"),
cors = require("cors"),
port = process.env.port || 3000,
app = express();
app.use(cors());
// assuming POST: name=foo&color=red <-- URL encoding
//
// or POST: {"name":"foo","color":"red"} <-- JSON encoding
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
app.get("/api-endpoint", (req, res) => {
console.log(req.query);
res.json({
greeting: "Thank-you for registering using GET Request",
requestData: req.query
});
});
app.post("/api-endpoint", (req, res) => {
console.log(req.body);
res.json({
greeting: "Thank-you for registering using POST Request",
requestData: req.body
});
});
if(!module.parent) {
app.listen(port, function() {
console.log('Express server listening on port ' + port + '.');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment