-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
59 lines (44 loc) · 1.85 KB
/
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
51
52
53
54
55
56
57
58
59
//Initial configuration
var express = require('express');
var app = express(); // create our app w/ express
var mongoose = require('mongoose'); // mongoose for mongodb
var bodyParser = require('body-parser'); // To fetch data during posts
var port = process.env.PORT || 8000; // set the port
var database = require('./config/database'); // load the database config
var db = mongoose.connect(database.url); // connect to mongoDB database on modulus.io
// auth related
var passport = require('passport');
var flash = require('connect-flash');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
//For loggin
var log4js = require("log4js");
var morgan = require('morgan');
// required for passport
app.use(session({ secret: 'jhhsdjakorijfsmdhtuypaswlmdjfk' })); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
//Middle-tier configuration
app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded
app.use(bodyParser.json()) // parse application/json
app.use(cookieParser())
//Log requests
var theAppLog = log4js.getLogger();
var theHTTPLog = morgan("combined",{
"stream": {
write: function(str) { theAppLog.debug(str); }
}
});
//app.use(theHTTPLog);
//static folder
app.use(express.static(__dirname + '/public')); // set the static files location
app.use(express.static(__dirname + '/scripts')); // set the static files location
// pass passport for configuration
require('./config/passport')(passport);
require('./app/routes.js')(app,passport);
//Start the awesomeness
app.listen(8080);
console.log('Magic happens on port 8080');