-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·87 lines (64 loc) · 2.2 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// server.js
// set all the dependencies
var express = require('express');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var app = express();
var port = 3010;
// Passport
var passport = require('passport');
var flash = require('connect-flash');
// Secure HTTPS
var https = require('https');
var fs = require('fs');
// DATABASE connection
var mysql = require('mysql');
var dbconfig = require('./config/database');
var connection = mysql.createConnection(dbconfig.connection);
// console.log(connection);
connection.query('USE ' + dbconfig.database);
// configuration
// connect to the database
require('./config/passport')(passport, connection); // pass passport and sql connection for configuration
// set up the express application
app.use(morgan('dev')); // log every request to the console
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
// Set view engine
app.set('view engine', 'ejs'); // set up ejs for templating
// required for passport
app.use(session({
secret: 'somesecretofprojectswe681passportnodejsgameproject',
resave: true,
saveUninitialized: true
} )); // 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
// Board database
// var board = require('./app/board.js');
// board.connection = this.connection;
// console.log(this.board);
// routes set up
var routing = require('./app/routes')(app, passport); // load our routes and pass in our app and fully configured passport
// ssl/tsl secure key and self-signed certificate generated using openssl
var options = {
key : fs.readFileSync('server.key'),
cert : fs.readFileSync('server.crt')
};
// Start the server
https.createServer(options, app).listen(port, function (err) {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on ${port}`)
});
// Set the admin user
var boardObj = require('./app/board');
boardObj.setUserRole("admin", "ADMIN", function(err, data) {
});