-
Notifications
You must be signed in to change notification settings - Fork 85
/
server.js
50 lines (42 loc) · 976 Bytes
/
server.js
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
"use strict";
/**
* Dependencies
*/
const fs = require("fs");
const koa = require("koa");
const mongoose = require("mongoose");
const passport = require("koa-passport");
/**
* Config
*/
const config = require("./config/config");
/**
* Connect to database
*/
mongoose.connect(config.mongo.url);
mongoose.connection.on("error", function(err) {
console.log(err);
});
/**
* Load the models
*/
const modelsPath = config.app.root + "/src/models";
fs.readdirSync(modelsPath).forEach(function(file) {
if (~file.indexOf("js")) {
require(modelsPath + "/" + file);
}
});
/**
* Server
*/
const app = module.exports = koa();
require("./config/passport")(passport, config);
require("./config/koa")(app, config, passport);
// Routes
require("./config/routes")(app, passport);
// Start app
if (!module.parent) {
app.listen(config.app.port);
console.log("Server started, listening on port: " + config.app.port);
}
console.log("Environment: " + config.app.env);