This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (49 loc) · 1.52 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
const express = require('express');
const passport = require('passport');
const SteamStrategy = require('passport-steam').Strategy;
const nunjucks = require('nunjucks');
const path = require('path');
require('dotenv').config();
const app = express();
const port = process.env.PORT || 3000;
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
app.use(passport.initialize());
app.use(express.static('static'))
app.set('view engine', 'njk');
nunjucks.configure(path.resolve(__dirname, 'views'), {
autoescape: true,
express: app,
watch: process.env.NODE_ENV !== 'production'
});
app.get('/', (_req, res) => res.render('login'));
app.get('/login', passport.authenticate('steam'));
app.get('/steam', passport.authenticate('steam', {
failureRedirect: '/'
}), (req, res) => {
const props = { ...req.user };
res.render('steam', props);
});
passport.use(new SteamStrategy({
returnURL: process.env.URL ? `${process.env.URL}/steam` : `http://localhost:${port}/steam`,
realm: process.env.URL || `http://localhost:${port}`,
apiKey: process.env.STEAM_API_KEY
}, (_identifier, profile, done) => {
const user = {
id: profile.id,
username: profile.displayName,
avatar: profile._json.avatarfull,
}
return done(null, user);
}));
app.use((_req, res) => {
res.redirect('/');
});
app.use((_err, _req, res, _next) => {
res.redirect('/');
});
app.listen(port, () => console.log(`Running on ${process.env.URL || `http://localhost:${port}/`}`));