-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
74 lines (56 loc) · 1.76 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
69
70
71
72
73
74
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const passport = require('passport');
const mongoose = require('mongoose');
const cors = require('cors');
require("dotenv").config();
//Initiate our app
const app = express();
const PORT = process.env.PORT || 3001;
//Configure our app
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json())
app.use(passport.initialize());
// Serve up static assets
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
// let root = path.join(__dirname, 'client', 'build');
// app.use(express.static(root));
// app.use(function(req, res, next) {
// if (req.method === 'GET' && req.accepts('html') && !req.is('json') &&
// !req.path.includes('.')) {
// res.sendFile('index.html', { root });
// } else next();
// });
app.use(session({
secret: 'countdown-project',
cookie: { maxAge: 60000 },
resave: false,
saveUninitialized: false
}))
// Configure Mongoose
mongoose.connect(
process.env.MONGODB_URI || "mongodb://localhost/countdown-project",
// process.env.MONGODB_URI || "mongodb://192.168.56.10/countdown-project",
{
useCreateIndex: true,
useNewUrlParser: true
}
);
mongoose.Promise = global.Promise;
mongoose.set('debug', true);
const routes = require('./routes');
require('./models');
// Configure Passport
const localSignupStrategy = require('./config/local-signup');
const localLoginStrategy = require('./config/local-login');
passport.use('local-signup', localSignupStrategy);
passport.use('local-login', localLoginStrategy);
app.use(routes);
// Start the API server
app.listen(PORT, () =>
console.log(`🌎 ==> API Server now listening on PORT ${PORT}!`)
);