github.com/orteth01/up@v0.2.0/http/relay/testdata/basic/app.js (about) 1 const http = require('http') 2 const port = process.env.PORT 3 4 http.createServer((req, res) => { 5 if (req.url.indexOf('/echo') == 0) { 6 const buffers = [] 7 req.on('data', b => buffers.push(b)) 8 req.on('end', _ => { 9 const body = Buffer.concat(buffers).toString() 10 res.setHeader('Content-Type', 'application/json') 11 res.end(JSON.stringify({ 12 header: req.headers, 13 url: req.url, 14 body 15 }, null, 2)) 16 }) 17 return 18 } 19 20 if (req.url.indexOf('/throw/random') == 0) { 21 if (Math.random() > 0.75) { 22 yaynode() 23 } 24 25 res.end('Hello') 26 return 27 } 28 29 if (req.url.indexOf('/throw/env') == 0) { 30 if (process.env.UP_RESTARTS != '2') { 31 yaynode() 32 } 33 34 res.end('Hello') 35 return 36 } 37 38 if (req.url.indexOf('/delay') == 0) { 39 setTimeout(function(){ 40 res.end('Hello') 41 }, Math.random() * 50000) 42 return 43 } 44 45 if (req.url.indexOf('/throw') == 0) { 46 yaynode() 47 } 48 49 res.setHeader('Content-Type', 'text/plain') 50 res.end('Hello World') 51 }).listen(port)