-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
95 lines (75 loc) · 2.18 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const express = require("express");
const path = require("path");
const logger = require("morgan");
const bodyParser = require("body-parser");
const cors = require('cors');
const methodOverride = require("method-override");
const cookieParser = require("cookie-parser");
var session = require('cookie-session');
const passport = require("passport");
var http = require('http');
require("dotenv").config();
const app = express();
// http.createServer(app).listen(80);
const PORT = process.env.PORT || 3002;
app.listen(PORT, function () {
console.log(`listening on port: ${PORT}`);
});
app.use(cors({
credentials: true, // <= Accept credentials (cookies) sent by the client
origin: function (origin, callback) {
return callback(null, true);
if (whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
},
// origin: "*", // (Whatever your frontend url is)
}));
app.options('*', cors());
app.use(logger("dev"));
app.use(methodOverride("_method"));
app.use(cookieParser('foo'));
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: false,
})
);
app.use(
session({
name: "__session",
keys: ["key1"],
maxAge: 24 * 60 * 60 * 100,
secure: false,
httpOnly: true,
sameSite: 'none',
secret: 'foo',
resave: true,
saveUninitialized: true,
cookie: {secure: false,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24
}
})
);
app.use(passport.initialize());
app.use(passport.session());
// =============== Routes =============== \\
const favRoutes = require("./routes/favRoutes");
const ebayRoutes = require("./routes/ebay");
const authRoutes = require("./routes/auth");
const userRoutes = require("./routes/users");
app.use("/fav", favRoutes);
app.use("/ebayApi", ebayRoutes);
app.use("/auth", authRoutes);
app.use("/api/user", userRoutes);
app.get("/api/test", function (req, res) {
res.json({
status: 'working',
})
});
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "client/build", "index.html"));
});