-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (35 loc) · 1.31 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
/**
* This is a node.js script that performs the Authorization Code oAuth2
* flow to authenticate against Spotify accounts.
*
* For more information about Spotify Auth Flow, read the following:
* https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow
**/
/* eslint-disable camelcase */
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser')
const express = require('express')
const path = require('path')
const cors = require('cors')
const PORT = process.env.NODE_PORT || 8081
const server = express()
/* CONFIGURE SERVER */
server.use(bodyParser.json())
server.use(bodyParser.urlencoded({ extended: true, }))
server.use(cookieParser())
server.use(cors())
/* CONFIGURE ROUTES */
server.use('/spotify', require('./routes/spotify'))
/* CONFIGURE NODE ENVIRONMENT */
if (process.env.NODE_ENV === 'production') {
const root = path.join(__dirname, 'client', 'build')
server.use(express.static(root));
server.get("*", (req, res) => {
res.sendFile('index.html', { root });
})}
else server.use(express.static(path.join(__dirname, 'client', 'public')))
/* LISTEN FOR TRAFFIC */
server.listen(PORT);
console.log(`finetune.io server listening on ${ PORT }`);
console.log(`Node environment set to ${ process.env.NODE_ENV }`);
/* eslint-enable */