-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
61 lines (52 loc) · 1.51 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
require("dotenv").config();
var express = require("express");
var app = express();
var routes = require('./routes');
var PORT = process.env.PORT || 3001;
var session = require('express-session');
// var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var db = require("./models");
var passport = require('./passport');
var path = require("path");
// Middleware
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
if(process.env.NODE_ENV === 'production'){
//set static folder
app.use(express.static('client/build'));
}
app.use(morgan('dev')); //log every request to the console
//for bodyParsar
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// required for passport
app.use(session({
// session secret
secret: 'condoapp',
resave: false,
saveUninitialized: false
} ));
// Passport
app.use(passport.initialize());
app.use(passport.session());
// Routes
app.use(routes);
require("./routes/apiRoutes.js")(app);
require("./routes/user.js")
app.get('*',(req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
var syncOptions = { force: false };
// Starting the server, syncing our models ------------------------------------/
db.sequelize.sync(syncOptions).then(function() {
app.listen(PORT, function() {
console.log(
"==> 🌎 Listening on port %s. Visit http://localhost:%s/ in your browser.",
PORT,
PORT
);
});
});
module.exports = app;