-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (41 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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const path = require("path");
const abilties = require('./routes/abilities');
const posts = require('./routes/posts');
const champions = require('./routes/champions');
const userSearch = require('./routes/userSearch');
const infoSearch = require('./routes/infoSearch');
const masterySearch = require('./routes/masterySearch');
const matchList = require('./routes/matchList');
const leaderboard = require('./routes/leaderboard');
const match = require('./routes/match');
// Retrieve API_Key from .env
const apiKey = process.env.LOL_API_KEY;
// Init server
const app = express();
// cors middleware - connects the server and client domain
app.use(cors());
// express middleware
app.use(express.json());
// Use Routes
app.use('/api/posts', posts);
app.use('/api/abilities', abilties);
app.use('/api/champions', champions);
app.use('/api/usersearch', userSearch);
app.use('/api/infosearch', infoSearch);
app.use('/api/masterysearch', masterySearch);
app.use('/api/matchlist', matchList);
app.use('/api/match', match);
app.use('/api/leaderboard', leaderboard)
if(process.env.NODE_ENV === 'production'){
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
})
}
// Create Port
const port = process.env.PORT || 5000;
// Listen in onto the Port
app.listen(port, () => console.log(`Server started on port ${port}`));