-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.js
63 lines (49 loc) · 1.78 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
const express = require('express');
const aws = require('aws-sdk');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const dotenv = require('dotenv');
const path = require('path');
const port = process.env.PORT || 5000;
const enterprises = require('./routes/api/enterprises');
const domains = require('./routes/api/domains');
const users = require('./routes/api/users');
const files = require('./routes/api/files');
const system_events = require('./routes/api/system_events')
const app = express();
// activate configuration variable
dotenv.config();
//Bodyparser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}))
// Fix deprecation warnings:
mongoose.set('useNewUrlParser', true);
mongoose.set('useCreateIndex', true);
mongoose.set('useUnifiedTopology', true);
//Connect to Mongo
mongoose
.connect(process.env.MONGODB_URI)
.then(() => console.log('connected to db...'))
.catch(err => console.log(err));
// Use Routes
app.use('/api/enterprises', enterprises);
app.use('/api/domains', domains);
app.use('/api/users', users);
app.use('/api/files', files);
app.use('/api/system_events', system_events);
// AWS config
aws.config.region = process.env.S3_BUCKET_REGION
aws.config.accessKeyId = process.env.AWS_ACCESS_KEY_ID
aws.config.secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
app.locals.JWT_SECRET = process.env.JWT_SECRET
app.locals.S3_BUCKET_NAME = process.env.S3_BUCKET_NAME
app.locals.S3_BUCKET_REGION = process.env.S3_BUCKET_REGION
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'));
});
}
app.listen(port, () => console.log(`Server started on port ${port}`));