-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (31 loc) · 1.31 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
const express = require("express");
const bodyParser = require("body-parser");
require("dotenv").config();
const mongoose = require("mongoose");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const passport = require("passport");
const app = express();
// const publicRoot = __dirname + "/client/dist";
// app.use(express.static(publicRoot));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(session({ secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());
mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useFindAndModify: false, useUnifiedTopology: true })
.then(() => {
console.log("Mongo database connected");
app.listen(process.env.PORT, () =>
console.log(`Server started on port ${process.env.PORT}`)
);
})
.catch(() => console.error("ERROR: Mongo database not connected:\n", process.env.MONGODB_URI));
// app.get("/", (req, res) => {
// res.sendFile("index.html", { root: publicRoot });
// });
const authRouter = require("./routes/auth")(passport);
app.use("/auth", authRouter);
const apiRoute = require("./routes/api")(passport);
app.use("/api/v1", apiRoute);