1
1
'use strict' ;
2
2
3
+ /**
4
+ * Module dependencies.
5
+ */
6
+
3
7
var express = require ( 'express' ) ,
4
8
http = require ( 'http' ) ,
5
9
path = require ( 'path' ) ,
6
- api = require ( './lib/api' ) ;
10
+ api = require ( './lib/routes/ api' ) ;
7
11
8
12
var app = express ( ) ;
9
13
10
- // all environments
11
- app . set ( 'port' , process . env . PORT || 3000 ) ;
14
+ // Configuration
12
15
13
- app . use ( express . logger ( 'dev' ) ) ;
14
- app . use ( express . bodyParser ( ) ) ;
15
- app . use ( express . methodOverride ( ) ) ;
16
- app . use ( app . router ) ;
16
+ app . configure ( function ( ) {
17
+ app . use ( express . logger ( 'dev' ) ) ;
18
+ app . use ( express . bodyParser ( ) ) ;
19
+ app . use ( express . methodOverride ( ) ) ;
20
+ app . use ( app . router ) ;
21
+ } ) ;
17
22
18
- // development only
19
- if ( 'development' === app . get ( 'env' ) ) {
23
+ app . configure ( 'development' , function ( ) {
20
24
app . use ( express . static ( path . join ( __dirname , '.tmp' ) ) ) ;
21
25
app . use ( express . static ( path . join ( __dirname , 'app' ) ) ) ;
22
26
app . use ( express . errorHandler ( ) ) ;
23
27
}
24
- // production only
25
- else {
28
+
29
+ app . configure ( 'production' , function ( ) {
26
30
app . use ( express . favicon ( path . join ( __dirname , 'public/favicon.ico' ) ) ) ;
27
31
app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
28
32
}
29
33
34
+ // Routes
35
+
30
36
app . get ( '/api/awesomeThings' , api . awesomeThings ) ;
31
37
32
- http . createServer ( app ) . listen ( app . get ( 'port' ) , function ( ) {
33
- console . log ( 'Express server listening on port %d in %s mode' , app . get ( 'port' ) , app . get ( 'env' ) ) ;
38
+ // Start server
39
+
40
+ var port = process . env . PORT || 3000 ;
41
+ app . listen ( port , function ( ) {
42
+ console . log ( 'Express server listening on port %d in %s mode' , app . address ( ) . port , app . get ( 'env' ) ) ;
34
43
} ) ;
0 commit comments