-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
68 lines (53 loc) · 1.82 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
// *** Dependencies
// =============================================================
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const passport = require("passport");
const session = require('express-session');
const PORT = process.env.PORT || 3001;
const express = require('express');
const path = require('path');
const app = express();
const config = require('./config')
const models = require("./models");
const cookieSession = require('cookie-session');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const LocalStrategy = require('passport-local').Strategy;
// Static assets
app.use(express.static("./client/build"));
app.use(express.static('./client/public'));
// Sets up the Express app to handle data parsing - AZ
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(passport.initialize());
// Passport
const localSignupStrategy = require('./passport/local-signup');
const localLoginStrategy = require('./passport/local-login');
passport.use('local-signup', localSignupStrategy);
passport.use('local-login', localLoginStrategy);
//routes
const routes = require("./routes")(passport);
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.use(routes);
// Mongo DataBase
mongoose.Promise = global.Promise;
if (process.env.MONGODB_URI) {
mongoose.connect(process.env.MONGODB_URI);
} else {
mongoose.connect(config.dbUri);
}
var db = mongoose.connection;
db.on('error', function (error) {
console.log('Mongoose Error: ', error);
});
db.once('open', function () {
console.log('Mongoose connection successful.');
});
// Start the API server
app.listen(PORT, function () {
console.log(`🌎 ==> API Server now listening on PORT ${PORT}!`);
});