1
1
'use strict' ;
2
2
3
- /**
4
- * Module dependencies.
5
- */
6
-
3
+ // Module dependencies.
7
4
var express = require ( 'express' ) ,
8
- http = require ( 'http' ) ,
9
- path = require ( 'path' ) ,
10
- api = require ( './lib/routes/api' ) ;
5
+ path = require ( 'path' ) < % if ( mongo ) { % > ,
6
+ fs = require ( 'fs' ) < % } % > ;
11
7
12
8
var app = express ( ) ;
9
+ < % if ( mongo ) { % >
10
+ // Connect to database
11
+ var db = require ( './lib/db/mongo' ) ;
12
+
13
+ // Bootstrap models
14
+ var modelsPath = path . join ( __dirname , 'lib/models' ) ;
15
+ fs . readdirSync ( modelsPath ) . forEach ( function ( file ) {
16
+ require ( modelsPath + '/' + file ) ;
17
+ } ) ;
13
18
14
- // Configuration
19
+ // Populate empty DB with dummy data
20
+ require ( './lib/db/dummydata' ) ;
21
+ < % } % >
22
+ // Controllers
23
+ var api = require ( './lib/controllers/api' ) ;
15
24
25
+ // Express Configuration
16
26
app . configure ( function ( ) {
17
27
app . use ( express . logger ( 'dev' ) ) ;
18
28
app . use ( express . bodyParser ( ) ) ;
@@ -24,20 +34,18 @@ app.configure('development', function(){
24
34
app . use ( express . static ( path . join ( __dirname , '.tmp' ) ) ) ;
25
35
app . use ( express . static ( path . join ( __dirname , 'app' ) ) ) ;
26
36
app . use ( express . errorHandler ( ) ) ;
27
- }
37
+ } ) ;
28
38
29
39
app . configure ( 'production' , function ( ) {
30
40
app . use ( express . favicon ( path . join ( __dirname , 'public/favicon.ico' ) ) ) ;
31
41
app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
32
- }
42
+ } ) ;
33
43
34
44
// Routes
35
-
36
45
app . get ( '/api/awesomeThings' , api . awesomeThings ) ;
37
46
38
47
// Start server
39
-
40
48
var port = process . env . PORT || 3000 ;
41
49
app . listen ( port , function ( ) {
42
- console . log ( 'Express server listening on port %d in %s mode' , app . address ( ) . port , app . get ( 'env' ) ) ;
50
+ console . log ( 'Express server listening on port %d in %s mode' , port , app . get ( 'env' ) ) ;
43
51
} ) ;
0 commit comments