-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
123 lines (97 loc) · 3.44 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const express = require("express");
require("dotenv").config();
const session = require("express-session");
const passport = require("passport");
const Auth0Strategy = require("passport-auth0");
const userInViews = require("./lib/middleware/userInViews");
const authRouter = require("./routes/auth");
const indexRouter = require("./routes/index");
const learnmoreRouter = require("./routes/learnmore");
const usersRouter = require("./routes/users");
const dashboardRouter = require("./routes/dashboard");
const cardgameRouter = require("./routes/cardgame-route");
const imageUpdateRouter = require("./routes/image-update");
const apiTeamMember = require("./routes/api-team_member");
const apiTeam = require("./routes/api-team_name");
const apiAnswer = require("./routes/api-answer");
const apiQuestion = require("./routes/api-question");
const PORT = process.env.PORT || 3000;
// Configure Passport to use Auth0
const strategy = new Auth0Strategy(
{
domain: process.env.AUTH0_DOMAIN,
clientID: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
callbackURL:
process.env.AUTH0_CALLBACK_URL || "http://localhost:3000/callback"
},
function (accessToken, refreshToken, extraParams, profile, done) {
// accessToken is the token to call Auth0 API (not needed in the most cases)
// extraParams.id_token has the JSON Web Token
// profile has all the information from the user
return done(null, profile);
}
);
passport.use(strategy);
// You can use this section to keep a smaller payload
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (user, done) {
done(null, user);
});
const app = express();
// Requiring our models for syncing
const db = require("./models");
// Serve static content for the app from the "public" directory in the application directory.
app.use(express.static("public"));
// Parse application body as JSON
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Set Handlebars.
const exphbs = require("express-handlebars");
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
const sess = {
secret: "Voorp voorp voorp",
cookie: {},
resave: false,
saveUninitialized: true
};
if (app.get("env") === "production") {
// Use secure cookies in production (requires SSL/TLS)
sess.cookie.secure = true;
// Uncomment the line below if your application is behind a proxy (like on Heroku)
// or if you're encountering the error message:
// "Unable to verify authorization request state"
app.set("trust proxy", 1);
}
app.use(session(sess));
app.use(passport.initialize());
app.use(passport.session());
// Import routes and give the server access to them.
// const routes = require("./routes/seq-test-routes.js");
// app.use(routes);
app.use(userInViews());
app.use("/", authRouter);
app.use("/", indexRouter);
app.use("/", usersRouter);
app.use("/", dashboardRouter);
app.use("/", learnmoreRouter);
app.use("/", cardgameRouter);
app.use("/", imageUpdateRouter);
app.use("/", apiTeamMember);
app.use("/", apiTeam);
app.use("/", apiAnswer);
app.use("/", apiQuestion);
// app.use("/cardgame", cardgameRouter);
// Syncing our database and logging a message to the user upon success
db.sequelize.sync().then(() => {
app.listen(PORT, () => {
console.log(
"==> 🌎 Listening on port %s. Visit http://localhost:%s/ in your browser.",
PORT,
PORT
);
});
});