-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (40 loc) · 1.8 KB
/
Copy pathapp.js
File metadata and controls
49 lines (40 loc) · 1.8 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
const express = require('express')
const session = require('express-session')
const passport = require('passport')
const exphbs = require('express-handlebars')
const consolidate = require('consolidate')
const swig = require('swig')
// Requiring our models for syncing
const db = require("./models");
// import configuration function for passport (it contains predefined strategy for Spotify)
const initializePassport = require('./config/passport-config')
initializePassport(passport);
// defaults for express
const PORT = process.env.PORT || 8888
const sessionSecret = process.env.SESSION_SECRET || 'whatever'
// create express
const app = express()
// configure express
app.engine('handlebars',exphbs({defaultLayout: "main"}))
app.set('view engine','handlebars')
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(session({
secret: sessionSecret, // each session will be secured with secret, it should be random string
resave: true, // should be false not sure yet
saveUninitialized: true })) // should be false not sure yet
app.use(passport.initialize()) // add middleware function
app.use(passport.session()) // add middleware function
app.use(express.static(__dirname + '/public')); // root directory for statuc content (images, js scripts, non-template html)
// import routes and give the server access to them.
const spotify_routes = require("./controllers/spotify");
const routes = require("./controllers/routes");
app.use(spotify_routes);
app.use(routes);
// Syncing our sequelize models and then starting our Express app
// =============================================================//
db.sequelize.sync({ force: false }).then(function() {
app.listen(PORT, function() {
console.log("App listening on PORT " + PORT);
});
});