-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (39 loc) · 1.14 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
var express = require("express");
var path = require("path")
var mongoose = require("mongoose");
const passport = require('passport')
// .env
require('dotenv').config()
// Initialize Express
var app = express();
var PORT = process.env.PORT || 3001;
// Require all models
var db = require("./models");
// Configure middleware
// Parse request body as JSON
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Make public a static folder
app.use(express.static("public"));
// passport middleware
app.use(passport.initialize());
// passport config
require ('./config/passport')(passport)
// Connect to the Mongo DB
mongoose
.connect(process.env.MONGODB_URI, { useNewUrlParser: true });
//Routes
require("./routes/api/users")(app)
if (process.env.NODE_ENV === 'production') {
// set static folder
app.use(express.static('client/build'));
}
// Send every other request to the React app
// Define any API routes before this runs
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
// Start the server
app.listen(PORT, function() {
console.log("App running on port " + PORT + "!");
});