-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
40 lines (33 loc) · 1.13 KB
/
server.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 path = require("path")
const express = require("express")
const favicon = require("serve-favicon")
const cookieParser = require("cookie-parser")
const bodyParser = require("body-parser")
const session = require("express-session")
const passport = require("passport")
const mongoose = require("mongoose")
require("dotenv").config()
require("./config/passport")
const authRoute = require("./routes/auth")
const apiRoute = require("./routes/api")
const port = process.env.PORT || "3000"
const app = express()
mongoose.connect(process.env.DB_URL)
app.use(favicon(path.join(__dirname, "public", "favicon.ico")))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(express.static(path.join(__dirname, "public")))
app.use("/auth", authRoute)
app.use("/api", apiRoute)
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"))
})
app.listen(port, () => console.log(`Server listening on port ${port}`))