forked from lokeshn011101/TeachieAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (47 loc) · 1.44 KB
/
index.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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const session = require("express-session");
const cors = require("cors");
const morgan = require("morgan");
const passport = require("passport");
const bodyParser = require("body-parser");
require("./models/UserInfo");
require("./Services/PassportOauth");
const keys = require("./config/keys");
const path = require("path");
mongoose.connect(keys.mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
app.use(
cors({
origin: "https://teachie-assistant.vercel.app/",
// allow to server to accept request from different origin
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true, // allow session cookie from browser to pass through
})
);
app.use(morgan("dev"));
app.use(
session({
resave: false,
saveUninitialized: true,
secret: "SECRET",
})
);
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(passport.initialize());
app.use(passport.session());
app.set("view engine", "html");
require("./Routes/authRoutes.js")(app);
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"));
});
}
const port = process.env.PORT || 5000;
app.listen(port, () => console.log("App listening on port " + port));