-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (49 loc) · 1.69 KB
/
script.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
const express = require("express")
const path = require("path");
const fs = require("fs")
const {Client} = require("pg")
const cors = require("cors");
const passport = require("passport");
const session = require("express-session")
require("dotenv").config(".env")
const app = express()
const node_env = "production" // in production
const client_url = node_env === "production" ? "http://13.40.189.125"
: "http://localhost:3000"
console.log(process.env.NODE_ENV)
app.use("/uploads", express.static("uploads"));
if(process.env.NODE_ENV === "production"){
app.use(express.static(path.join(__dirname, "client/build")))
}
// body parser middleware
app.use(express.json()) // for json body
app.use(express.urlencoded({extended: false})) // for form submission body
app.use(session({
resave: false,
saveUninitialized: true,
secret: "testsecret"
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(cors())
const logger = (req, res, next) => {
console.log(req.originalUrl)
next()
}
app.use(logger)
app.use("/api/users", require("./routes/api/users.js"))
app.use("/api/posts", require("./routes/api/posts.js"))
app.use("/api/media", require("./routes/api/media.js"))
app.get("/google", passport.authenticate("google", {scope: ["profile"]}))
app.get("/google/callback", passport.authenticate("google"), async(req, res) => {
console.log(req.user)
res.redirect(`${client_url}/oauth-login?token=${req.user.token}`)
})
app.get("/test", (req, res) => {
res.status(302).redirect("https://google.com")
})
const PORT = process.env.PORT || 5000
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client/build/index.html"))
})
app.listen(PORT, () => console.log(`running on port ${PORT}`))