-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
68 lines (57 loc) · 1.61 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
60
61
62
63
64
65
66
67
68
require("dotenv").config();
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const express = require("express");
const mongoose = require("mongoose");
const logger = require("morgan");
const path = require("path");
const cors = require("cors");
const session = require("express-session");
mongoose
.connect(
process.env.NODE_ENV === "development"
? "mongodb://localhost/backend"
: process.env.DB,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
}
)
.then((x) =>
console.log(`Connected to Mongo! Database name: "${x.connections[0].name}"`)
)
.catch((err) => console.error("Error connecting to mongo", err));
const app_name = require("./package.json").name;
const debug = require("debug")(
`${app_name}:${path.basename(__filename).split(".")[0]}`
);
const app = express();
app.use(
cors({
credentials: true,
origin: [process.env.FRONTENDPOINT],
})
);
app.use(
session({
resave: false,
saveUninitialized: true,
secret: process.env.SECRET,
cookie: { maxAge: 1000 * 60 * 60 },
})
);
require("./config/passport")(app);
app.use(express.static(path.join(__dirname, "public/build")));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(logger("dev"));
const index = require("./routes/index.routes");
app.use("/api", index);
app.use("/auth", require("./routes/auth.routes"));
// Uncomment this line for production
app.get("/*", (req, res) =>
res.sendFile(__dirname + "/public/build/index.html")
);
module.exports = app;