forked from linnovate/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·87 lines (62 loc) · 1.73 KB
/
server.js
File metadata and controls
executable file
·87 lines (62 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Generated by CoffeeScript 1.6.3
"use strict";
/*
Module dependencies.
*/
var app, config, db, exports, express, fs, logger, models_path, mongoose, passport, port, routes_path, walk;
express = require("express");
fs = require("fs");
passport = require("passport");
logger = require("mean-logger");
/*
Main application entry file.
Please note that the order of loading is important.
*/
process.env.NODE_ENV = process.env.NODE_ENV || "development";
config = require("./config/config");
mongoose = require("mongoose");
db = mongoose.connect(config.db);
models_path = __dirname + "/app/models";
walk = function(path) {
return fs.readdirSync(path).forEach(function(file) {
var newPath, stat;
newPath = path + "/" + file;
stat = fs.statSync(newPath);
if (stat.isFile()) {
if (/(.*)\.(js$)/.test(file)) {
return require(newPath);
}
} else {
if (stat.isDirectory()) {
return walk(newPath);
}
}
});
};
walk(models_path);
require("./config/passport")(passport);
app = express();
require("./config/express")(app, passport, db);
routes_path = __dirname + "/app/routes";
walk = function(path) {
return fs.readdirSync(path).forEach(function(file) {
var newPath, stat;
newPath = path + "/" + file;
stat = fs.statSync(newPath);
if (stat.isFile()) {
if (/(.*)\.(js$|coffee$)/.test(file)) {
return require(newPath)(app, passport);
}
} else {
if (stat.isDirectory() && file !== "middlewares") {
return walk(newPath);
}
}
});
};
walk(routes_path);
port = process.env.PORT || config.port;
app.listen(port);
console.log("Express app started on port " + port);
logger.init(app, passport, mongoose);
exports = module.exports = app;