-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
60 lines (49 loc) · 1.43 KB
/
server.js
File metadata and controls
60 lines (49 loc) · 1.43 KB
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
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const path = require('path');
const dotenv = require('dotenv').config();
const models = require('./server/models');
const routes = require('./server/routes');
const passport = require('passport');
// If we are not running production, use local keys
if (!process.env.NODE_ENV) {
var config = require('./server/config/keys');
};
const app = express();
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, '/client/build')));
// Allowed origins
const corsOptions = {
origin: `${process.env.ALLOWED_ORIGINS}` || config.ALLOWED_ORIGINS,
optionsSuccessStatus: 200
};
app.use(cors(corsOptions));
// bodyparser
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
app.use(passport.initialize());
app.use(passport.session());
// routes
app.use('/', routes);
// Handles any requests that do not match the ones above
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'));
});
const PORT = process.env.PORT || 5000;
app.listen(PORT, (err) => {
if (!err) {
models.sequelize.sync()
.then(() => {
console.log('Database is running');
})
.catch((err) => {
console.log(err, 'Something went wrong with the Database update');
});
console.log('Site is live');
} else {
console.log('err');
};
});