1
1
#!/usr/bin/env node
2
2
3
3
var express = require ( 'express' ) ;
4
+ var bodyParser = require ( 'body-parser' )
4
5
var optimist = require ( 'optimist' ) ;
5
6
var util = require ( 'util' ) ;
6
7
var path = require ( 'path' ) ;
@@ -21,6 +22,10 @@ var angularDir = path.join(testAppDir, 'ng1/lib/angular_v' + argv.ngversion);
21
22
22
23
var main = function ( ) {
23
24
var port = argv . port ;
25
+ testApp . use ( '/ng1/lib/angular' , express . static ( angularDir ) ) ;
26
+ testApp . use ( express . static ( testAppDir ) ) ;
27
+ testApp . use ( bodyParser . json ( ) ) ;
28
+ testApp . use ( testMiddleware ) ;
24
29
testApp . listen ( port ) ;
25
30
util . puts ( [ "Starting express web server in" , testAppDir , "on port" , port ] .
26
31
join ( " " ) ) ;
@@ -29,52 +34,45 @@ var main = function() {
29
34
var storage = { } ;
30
35
var testMiddleware = function ( req , res , next ) {
31
36
if ( / n g [ 1 - 2 ] \/ f a s t c a l l / . test ( req . path ) ) {
32
- res . send ( 200 , 'done' ) ;
37
+ res . status ( 200 ) . send ( 'done' ) ;
33
38
} else if ( / n g [ 1 - 2 ] \/ s l o w c a l l / . test ( req . path ) ) {
34
39
setTimeout ( function ( ) {
35
- res . send ( 200 , 'finally done' ) ;
40
+ res . status ( 200 ) . send ( 'finally done' ) ;
36
41
} , 5000 ) ;
37
42
} else if ( / n g [ 1 - 2 ] \/ f a s t T e m p l a t e U r l / . test ( req . path ) ) {
38
- res . send ( 200 , 'fast template contents' ) ;
43
+ res . status ( 200 ) . send ( 'fast template contents' ) ;
39
44
} else if ( / n g [ 1 - 2 ] \/ s l o w T e m p l a t e U r l / . test ( req . path ) ) {
40
45
setTimeout ( function ( ) {
41
- res . send ( 200 , 'slow template contents' ) ;
46
+ res . status ( 200 ) . send ( 'slow template contents' ) ;
42
47
} , 5000 ) ;
43
48
} else if ( / n g [ 1 - 2 ] \/ c h a t / . test ( req . path ) ) {
44
49
if ( req . method === 'GET' ) {
45
50
var value ;
46
51
if ( req . query . q ) {
47
52
value = storage [ req . query . q ] ;
48
- res . send ( 200 , value ) ;
53
+ res . status ( 200 ) . send ( value ) ;
49
54
} else {
50
- res . send ( 400 , 'must specify query' ) ;
55
+ res . status ( 400 ) . send ( 'must specify query' ) ;
51
56
}
52
57
} else if ( req . method === 'POST' ) {
53
58
if ( req . body . key == 'newChatMessage' ) {
54
59
if ( ! storage [ 'chatMessages' ] ) {
55
60
storage [ 'chatMessages' ] = [ ] ;
56
61
}
57
62
storage [ 'chatMessages' ] . push ( req . body . value ) ;
58
- res . send ( 200 ) ;
63
+ res . sendStatus ( 200 ) ;
59
64
} else if ( req . body . key == 'clearChatMessages' ) {
60
65
storage [ 'chatMessages' ] = [ ] ;
61
- res . send ( 200 ) ;
66
+ res . sendStatus ( 200 ) ;
62
67
} else {
63
- res . send ( 400 , 'Unknown command' ) ;
68
+ res . status ( 400 ) . send ( 'Unknown command' ) ;
64
69
}
65
70
} else {
66
- res . send ( 400 , 'only accepts GET/POST' ) ;
71
+ res . status ( 400 ) . send ( 'only accepts GET/POST' ) ;
67
72
}
68
73
} else {
69
74
return next ( ) ;
70
75
}
71
76
} ;
72
77
73
- testApp . configure ( function ( ) {
74
- testApp . use ( '/ng1/lib/angular' , express . static ( angularDir ) ) ;
75
- testApp . use ( express . static ( testAppDir ) ) ;
76
- testApp . use ( express . json ( ) ) ;
77
- testApp . use ( testMiddleware ) ;
78
- } ) ;
79
-
80
78
main ( ) ;
0 commit comments