1
- const bodyParser = require ( 'body-parser' ) ;
2
- const express = require ( 'express' ) ;
1
+ var bodyParser = require ( 'body-parser' ) ;
2
+ var express = require ( 'express' ) ;
3
3
4
4
// This server provides useful routes for testing various AJAX requests
5
5
6
- const app = express ( ) ;
6
+ var app = express ( ) ;
7
7
8
8
// Parse all request bodies into string, no decoding
9
9
app . use ( bodyParser . text ( { type : '*/*' } ) ) ;
10
10
11
- app . get ( '/simple-get' , ( req , res , next ) => res . send ( 'hello' ) ) ;
12
- app . get ( '/nested/simple-get' , ( req , res , next ) => res . send ( 'nested hello' ) ) ;
13
- app . post ( '/dump-request-body' , ( req , res , next ) => res . send ( req . body ) ) ;
14
- app . get ( '/dump-headers' , ( req , res , next ) => res . send (
15
- Object . keys ( req . headers ) . sort ( ) . map ( name => `${ name } : ${ req . headers [ name ] } ` ) . join ( '\n' )
16
- ) ) ;
17
- app . get ( '/dump-query' , ( req , res , next ) => res . send (
18
- Object . keys ( req . query ) . sort ( ) . map ( key => `${ key } : ${ req . query [ key ] } ` ) . join ( '\n' )
19
- ) ) ;
20
- app . post ( '/validate-urlencoded-request' , ( req , res , next ) => {
11
+ app . get ( '/simple-get' , function ( req , res ) {
12
+ return res . send ( 'hello' ) ;
13
+ } ) ;
14
+ app . get ( '/nested/simple-get' , function ( req , res ) {
15
+ return res . send ( 'nested hello' ) ;
16
+ } ) ;
17
+ app . post ( '/dump-request-body' , function ( req , res ) {
18
+ return res . send ( req . body ) ;
19
+ } ) ;
20
+ app . get ( '/dump-headers' , function ( req , res ) {
21
+ return res . send ( Object . keys ( req . headers ) . sort ( ) . map ( function ( name ) {
22
+ return "" . concat ( name , ": " ) . concat ( req . headers [ name ] ) ;
23
+ } ) . join ( '\n' ) ) ;
24
+ } ) ;
25
+ app . get ( '/dump-query' , function ( req , res ) {
26
+ return res . send ( Object . keys ( req . query ) . sort ( ) . map ( function ( key ) {
27
+ return "" . concat ( key , ": " ) . concat ( req . query [ key ] ) ;
28
+ } ) . join ( '\n' ) ) ;
29
+ } ) ;
30
+ app . post ( '/validate-urlencoded-request' , function ( req , res ) {
21
31
if ( req . headers [ 'content-type' ] !== 'application/x-www-form-urlencoded' ) {
22
32
res . status ( 400 ) . send ( 'FAIL (header)' ) ;
23
33
} else if ( req . body !== 'hello=there&whats=up' ) {
@@ -26,7 +36,7 @@ app.post('/validate-urlencoded-request', (req, res, next) => {
26
36
res . set ( 'content-type' , 'text/plain' ) . send ( 'PASS' ) ;
27
37
}
28
38
} ) ;
29
- app . post ( '/validate-json-request' , ( req , res , next ) => {
39
+ app . post ( '/validate-json-request' , function ( req , res ) {
30
40
if ( req . headers [ 'content-type' ] !== 'application/json' ) {
31
41
res . status ( 400 ) . send ( 'FAIL (header)' ) ;
32
42
} else {
@@ -37,10 +47,24 @@ app.post('/validate-json-request', (req, res, next) => {
37
47
}
38
48
}
39
49
} ) ;
40
- app . get ( '/dummy-headers' , ( req , res , next ) => res . set ( { 'x-dummy' : 'definitely' } ) . send ( '' ) ) ;
41
- app . get ( '/json-payload' , ( req , res , next ) => res . set ( 'content-type' , 'application/json' ) . send ( '{"taker":"believer"}' ) ) ;
42
- app . get ( '/json-payload-fail' , ( req , res , next ) => res . status ( 400 ) . set ( 'content-type' , 'application/json' ) . send ( '{"taker":"believer"}' ) ) ;
43
- app . get ( '/specific-status' , ( req , res , next ) => res . status ( req . query . give ) . send ( '' ) ) ;
44
- app . get ( '/specific-timeout' , ( req , res , next ) => setTimeout ( ( ) => res . send ( 'made it' ) , req . query . wait ) ) ;
50
+ app . get ( '/dummy-headers' , function ( req , res ) {
51
+ return res . set ( {
52
+ 'x-dummy' : 'definitely'
53
+ } ) . send ( '' ) ;
54
+ } ) ;
55
+ app . get ( '/json-payload' , function ( req , res ) {
56
+ return res . set ( 'content-type' , 'application/json' ) . send ( '{"taker":"believer"}' ) ;
57
+ } ) ;
58
+ app . get ( '/json-payload-fail' , function ( req , res ) {
59
+ return res . status ( 400 ) . set ( 'content-type' , 'application/json' ) . send ( '{"taker":"believer"}' ) ;
60
+ } ) ;
61
+ app . get ( '/specific-status' , function ( req , res ) {
62
+ return res . status ( req . query . give ) . send ( '' ) ;
63
+ } ) ;
64
+ app . get ( '/specific-timeout' , function ( req , res ) {
65
+ return setTimeout ( function ( ) {
66
+ return res . send ( 'made it' ) ;
67
+ } , req . query . wait ) ;
68
+ } ) ;
45
69
46
70
module . exports = app ;
0 commit comments