-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
64 lines (44 loc) · 1.49 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
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const path = require('path');
// environment variables
require('dotenv').config();
const app = express();
app.use(cors());
app.use(express.json());
const port = process.env.PORT || 4000;
app.set('port', port);
// database connection
const uri = process.env.URI;
mongoose.connect(uri, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
}).catch(err => console.log(err));
const connection = mongoose.connection;
connection.once('open', () => {
console.log('Mongodb connection successful');
});
// ----- ROUTES
const user = require('./routes/auth.routes');
app.use('/user', user);
const trackList = require('./routes/list.routes');
app.use('/trackList', trackList);
const movieList = require('./routes/movie.list.routes');
app.use('/movie', movieList);
const tvShowList = require('./routes/tvShow.list.routes');
app.use('/tvShow', tvShowList);
const animeList = require('./routes/anime.list.routes');
app.use('/anime', animeList);
const wishList = require('./routes/wish.list.routes');
app.use('/wishList', wishList);
const publicPath = path.join(__dirname, 'frontend', 'build');
app.use(express.static(publicPath));
app.get('/user', (req, res) => res.json({name: 'req'}));
app.get('*',(req, res) => {
res.sendFile(path.join(publicPath, 'index.html'));
})
app.listen(port, function () {
console.log(`Server up and running on port ${port}`);
});