Advertisement
NLinker

Simple request bin

May 25th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express')
  2. const bodyParser = require('body-parser')
  3. const app = express()
  4.  
  5. //app.use(express.static('www'))
  6. app.use(bodyParser.json())
  7.  
  8. app.use(function (err, req, res, _next) {
  9.   console.error(err.stack)
  10.   res.status(500).send('Something is broken!')
  11. })
  12.  
  13. //-----------------------------------------------------------------
  14. app.get('*', (req, res) => {
  15.   console.log('GET', req.hostname, req.url, req.headers, req.body)
  16.   res.send({})
  17. })
  18.  
  19. app.post('*', (req, res) => {
  20.   console.log('POST', req.hostname, req.url, req.headers, req.body)
  21.   res.send({})
  22. })
  23.  
  24. app.put('*', (req, res) => {
  25.   console.log('POST', req.hostname, req.url, req.headers, req.body)
  26.   res.send({})
  27. })
  28.  
  29. app.delete('*', (req, res) => {
  30.   console.log('POST', req.hostname, req.url, req.headers, req.body)
  31.   res.send({})
  32. })
  33.  
  34. /* Use PORT environment variable if it exists */
  35. const port = process.env.PORT || 8080
  36. server = app.listen(port, function () {
  37.   console.log('Server listening on port %d in %s mode', port, app.settings.env)
  38. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement