()
| 6 | declare const process: any; |
| 7 | |
| 8 | export function startServer() { |
| 9 | const app = express(); |
| 10 | |
| 11 | app.use(function(req, res, next) { |
| 12 | res.set('Cache-Control', 'no-cache, no-store'); |
| 13 | next(); |
| 14 | }); |
| 15 | app.use(bodyParser.urlencoded({ extended: true })); |
| 16 | app.use(bodyParser.json()); |
| 17 | app.use(cookieParser()); |
| 18 | |
| 19 | app.get('/hello', function(req, res){ |
| 20 | setTimeout(function () { |
| 21 | const contentTypeHeader = req.get('Content-Type'); |
| 22 | if (!contentTypeHeader) { |
| 23 | res.send('Hello World'); |
| 24 | } else { |
| 25 | res.status(500).send( |
| 26 | 'Expected Content-Type request header to be undefined, but got ' + contentTypeHeader, |
| 27 | ); |
| 28 | } |
| 29 | }, 150); |
| 30 | }); |
| 31 | |
| 32 | app.post('/pet', function(req, res){ |
| 33 | setTimeout(function () { |
| 34 | const result = 'added ' + req.body.name + ' the ' + req.body.species; |
| 35 | (globalSandbox as any).petPOSTResponse = result; |
| 36 | res.send(result); |
| 37 | }, 150); |
| 38 | }); |
| 39 | |
| 40 | app.get('/json', function(req, res){ |
| 41 | setTimeout(function () { |
| 42 | res.status(200).json({ name: 'manny' }); |
| 43 | }, 150); |
| 44 | }); |
| 45 | |
| 46 | app.get('/querystring', function(req, res){ |
| 47 | setTimeout(function () { |
| 48 | res.send(req.query); |
| 49 | }, 150); |
| 50 | }); |
| 51 | |
| 52 | app.get('/error', function(req, res){ |
| 53 | setTimeout(function () { |
| 54 | res.status(500).send('boom'); |
| 55 | }, 150); |
| 56 | }); |
| 57 | |
| 58 | app.delete('/delete', function(req, res){ |
| 59 | setTimeout(function () { |
| 60 | res.status(200).json({deleted: true}); |
| 61 | }, 150); |
| 62 | }); |
| 63 | |
| 64 | app.listen(process.env.PORT); |
| 65 | } |
no test coverage detected