-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (40 loc) · 1.46 KB
/
server.js
File metadata and controls
55 lines (40 loc) · 1.46 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
const express = require("express");
const path = require("path");
const passport = require("passport");
const PORT = process.env.PORT || 5000;
const mongoose = require("mongoose");
require('dotenv').config()
const logger = require("morgan");
const app = express();
// Use morgan logger for logging requests
app.use(logger("dev"));
// Express middleware
app.use(express.urlencoded({ extended: true })); // Bodyparser
app.use(express.json());
// Passport middleware
app.use(passport.initialize());
// Passport config
require("./config/passport")(passport);
// Routes
require("./routes/api/user")(app);
// Models
// Requiring the `User` model for accessing the `users` collection
const User = require("./models/User");
const db = require("./config/keys").SECRET_OR_KEY;
// Connect to the Mongo DB
mongoose.connect("mongodb://stylsTest:password1@ds229088.mlab.com:29088/heroku_3cclhw95", { useNewUrlParser: true })
.then(() => console.log("MongoDB connected!"))
.catch(err => console.log("There was an issue with the db connection" + err));
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(
path.resolve(__dirname, "client", "build", "index.html"));
});
}
// Send every other request to the React app
// Define any API routes before this runs
app.listen(PORT, () => {
console.log(`🌎 ==> API server now on port ${PORT}!`);
});