-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (42 loc) · 1.4 KB
/
app.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
require("dotenv").config();
const express = require("express");
const logger = require("morgan");
const SpotifyWebApi = require('spotify-web-api-node');
const flash = require ("connect-flash");
require("./config/db.config");
require("./config/hbs.config");
const app = express();
app.set("view engine", "hbs");
app.set("views", `${__dirname}/views`);
const spotifyApi = new SpotifyWebApi({
clientId: process.env.CLIENT_SPOTIFY_ID,
clientSecret: process.env.CLIENT_SPOTIFY_SECRET
});
// Retrieve an access token
spotifyApi
.clientCredentialsGrant()
.then(data => spotifyApi.setAccessToken(data.body['access_token']))
.catch(error => console.log('Something went wrong when retrieving an access token', error));
app.use(express.urlencoded({ extended: true }));
app.use(express.static("public"));
app.use(logger("dev"));
const sessionConfig = require('./config/session.config');
app.use(sessionConfig.session);
app.use(sessionConfig.loadSessionUser);
app.use(flash());
app.use((req, res, next) => {
res.locals.navigationPath = req.path;
const fashData = req.flash('data');
// console.log(fashData);
if (fashData?.length > 0) {
const data = JSON.parse(fashData[0]);
Object.keys(data)
.forEach((key) => res.locals[key] = data[key])
}
next();
})
const router = require("./config/routes.config");
app.use("/", router);
app.listen(process.env.PORT || 3000, () => {
console.log("Ready!");
});