11'use strict' ;
22
3+ /**
4+ * Module dependencies.
5+ */
6+
37var express = require ( 'express' ) ,
48 http = require ( 'http' ) ,
59 path = require ( 'path' ) ,
6- api = require ( './lib/api' ) ;
10+ api = require ( './lib/routes/ api' ) ;
711
812var app = express ( ) ;
913
10- // all environments
11- app . set ( 'port' , process . env . PORT || 3000 ) ;
14+ // Configuration
1215
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+ } ) ;
1722
18- // development only
19- if ( 'development' === app . get ( 'env' ) ) {
23+ app . configure ( 'development' , function ( ) {
2024 app . use ( express . static ( path . join ( __dirname , '.tmp' ) ) ) ;
2125 app . use ( express . static ( path . join ( __dirname , 'app' ) ) ) ;
2226 app . use ( express . errorHandler ( ) ) ;
2327}
24- // production only
25- else {
28+
29+ app . configure ( 'production' , function ( ) {
2630 app . use ( express . favicon ( path . join ( __dirname , 'public/favicon.ico' ) ) ) ;
2731 app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
2832}
2933
34+ // Routes
35+
3036app . get ( '/api/awesomeThings' , api . awesomeThings ) ;
3137
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' ) ) ;
3443} ) ;
0 commit comments