-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
39 lines (36 loc) · 1.17 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
const express = require('express');
const logger = require('morgan');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('passport');
const path = require('path');
require('dotenv').config();
// express server
const app = express();
const port = process.env.PORT || 8080;
// middleware
app.use(cors())
app.use(express.json());
app.use(logger('dev'));
// passport authentication
app.use(cookieParser());
app.use(session({secret: process.env.SECRET_KEY, resave: false, saveUninitialized: true}));
app.use(passport.initialize());
app.use(passport.session());
if(process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});
}
app.listen(port, () => {
console.log(`Currently listening on port ${port}`);
});
// routes
const songsRouter = require('./routes/songs');
const usersRouter = require('./routes/users');
const authRouter = require('./routes/auth');
app.use('/auth', authRouter);
app.use('/songs', songsRouter);
app.use('/profile', usersRouter);