-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (60 loc) · 2.02 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
65
66
67
68
require('dotenv').config();
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const cloudinary = require('cloudinary').v2;
const cookieParser = require('cookie-parser');
const http = require('http').createServer(app);
const io = require('./websocket/sockets').listen(http);
const path = require('path');
// local files
const announcements = require('./routes/announcements');
const auth = require('./routes/auth');
const events = require('./routes/events');
const manager = require('./routes/manager');
const user = require('./routes/user');
const wod = require('./routes/wod');
const wodweek = require('./routes/wodweek');
const mongoose = require('mongoose');
// mongoose.connect('mongodb://localhost/fcf_backend', {
// useNewUrlParser: true,
// useCreateIndex: true,
// }); // for local dev
mongoose.connect(process.env.FOUNDATION_DB_URI, {
useNewUrlParser: true,
}); // for heroku deployment
// add this in client package.json for local dev after scripts
// "proxy": "http://localhost:3001",
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
app.io = io;
// libraries
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
// local folders
app.use('/announcements', announcements);
app.use('/auth', auth);
app.use('/events', events);
app.use('/manager', manager);
app.use('/user', user);
app.use('/wod', wod);
app.use('/wodweek', wodweek);
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
}
// npm run dev to run in dev mode
const PORT = process.env.PORT || 3001;
// app.listen(PORT, () => {
// console.log(`App listening on port ${PORT}!`)
// });
http.listen(PORT, function () {
console.log(`Http is listening on port ${PORT}...`);
});
module.exports = app;