Skip to content

Instantly share code, notes, and snippets.

@markwithers
Created February 20, 2018 20:06
Show Gist options
  • Save markwithers/d688e3efe26d2288bfe558dd73af2f72 to your computer and use it in GitHub Desktop.
Save markwithers/d688e3efe26d2288bfe558dd73af2f72 to your computer and use it in GitHub Desktop.
var express = require('express')
var app = express()
var port = process.env.PORT || 8080
var router = express.Router()
router.get('/', function(req, res) {
res.json({ message: 'Welcome to the api!' })
})
router.get('/safe', function(req, res) {
res.json({ message: 'You got a success!' })
})
router.get('/risky', function(req, res) {
if (Math.random() > 0.5) {
res.json({ message: 'You got a success!' })
}
else {
res.status(418).send('This is a teapot')
}
})
app.use('/api', router)
app.listen(port)
console.log('listening on port ' + port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment