-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
70 lines (60 loc) · 1.92 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
/********** CRYPTOTRACKER APP **********/
// Setting up app dependencies
const express = require('express');
const bodyParser = require('body-parser');
const passport = require('passport');
const session = require('express-session');
const env = require('dotenv').load();
// Create Express server and set the PORT
const app = express();
const PORT = process.env.PORT || 4000;
// Requiring mdoels for syncing
var db = require('./models');
// Sets up the Express app to handle data parsing
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.text());
app.use(bodyParser.json({
type: "application/vnd.api+json"
}));
// Set up middleware: passport and express session
app.use(session({
secret: 'somethingsecretive',
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
// Sets up Express to use handlebars
const exphbs = require('express-handlebars');
app.engine('handlebars', exphbs({
defaultLayout: 'main'
}));
app.set('view engine', 'handlebars');
// static files under public folder need express setup
app.use(express.static(__dirname + '/public'));
// Sets up ROUTES
require('./routes/html-routes.js')(app);
require('./routes/api-routes.js')(app);
require('./routes/user-routes.js')(app);
require('./routes/favorite-routes.js')(app);
var authRoute = require('./routes/auth.js')(app, passport);
// load passport strategies
require('./config/passport.js')(passport, db.user);
// load coinmarket API data into mysql
const coinDataAPI = require('./config/coinmarket.js');
// Listening on PORT, Syncing Sequelize models and starting Express app
db.sequelize.sync({
force: false // true will drop database
}).then(function () {
app.listen(PORT, function (err) {
if (!err) {
coinDataAPI.coinData();
console.log("App listening on PORT " + PORT);
} else {
console.log(err);
}
});
});