-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (50 loc) · 1.47 KB
/
app.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
require("dotenv").config();
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const express = require("express");
const favicon = require("serve-favicon");
const mongoose = require("mongoose");
const logger = require("morgan");
const path = require("path");
const cors = require("cors");
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);
const passportSetup = require("./config/passport");
mongoose.Promise = Promise;
mongoose
.connect(
process.env.MONGODB_URI,
{ useMongoClient: true }
)
.then(() => {
console.log("Connected to Mongo!");
})
.catch(err => {
console.error("Error connecting to mongo", err);
});
const app = express();
// Middleware Setup
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(favicon(path.join(__dirname, "public", "images", "favicon.ico")));
app.use(cors({
credentials: true,
origin: process.env.CLIENT_URL,
}));
app.use(
session({
secret: "blah blah blah",
saveUninitialized: true,
resave: true,
store: new MongoStore({ mongooseConnection: mongoose.connection })
})
);
passportSetup(app);
const userRouter = require("./routes/userRoutes");
app.use("/api", userRouter);
const projectRouter = require("./routes/projectsRoutes");
app.use("/api", projectRouter);
module.exports = app;