-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
144 lines (106 loc) · 3.51 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const express = require('express');
const path = require('path');
const passport = require('passport');
const session = require('express-session')
const SteamStrategy = require('passport-steam').Strategy;
const fileupload = require('express-fileupload');
const exp = require('constants');
const { initializeApp } = require("firebase/app")
const { getFirestore, addDoc, collection, getDocs, setDoc, doc } = require('firebase/firestore');
const { kMaxLength } = require('buffer');
const steaminventory = require('get-steam-inventory');
let initial_path = path.join(__dirname, "views");
// Firebase Setup
const firebaseConfig = {
apiKey: process.env.apiKey,
authDomain: process.env.authDomain,
databaseURL: process.env.databaseURL,
projectId: process.env.databaseURL,
storageBucket: process.env.storageBucket,
messagingSenderId: process.env.messagingSenderId,
appId: process.env.appId,
measurementId: process.env.measurementId
};
const fApp = initializeApp(firebaseConfig);
let db = getFirestore(fApp);
// Passport Setup
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
passport.use(new SteamStrategy({
returnURL: 'https://skindb.onrender.com/auth/steam/return',
realm: 'https://skindb.onrender.com/',
apiKey: process.env.steamApiKey
},
function(identifier, profile, done) {
process.nextTick(function () {
profile.identifier = identifier;
return done(null, profile);
});
}
));
// App Setup
const app = express();
app.set('views', __dirname + '/views');
app.engine('ejs', require('ejs').renderFile);
app.set('view engine', 'ejs');
app.use(session({
secret: 'testSecret',
name: 'testName',
resave: true,
saveUninitialized: true}));
app.use(express.static(initial_path));
app.use(express.json())
app.use(express.urlencoded());
app.use(fileupload());
app.use(passport.initialize());
app.use(passport.session());
// Routing
app.get('/', (req, res) => {
res.sendFile(path.join(initial_path, "landing.html"));
})
app.get('/main', (req, res) => {
res.render("main", {user:req.user});
})
app.get('/dashboard', async function(req, res){
if(req.user){
let data = await steaminventory.getinventory(730, req.user.id, '2');
setDoc(doc(db, "test-collection", req.user.id), {invData :data.raw.descriptions, profilePicture : req.user.photos[2].value, displayName : req.user.displayName});
res.render("dashboard", {user :req.user, invData : data.raw.descriptions});
}
else{
res.render("dashboard", {user :null, invData : null});
}
//res.sendFile(path.join(initial_path, "dashboard.html"));
})
app.get("/test", (req, res) => {
res.sendFile(path.join(initial_path, "tester.html"))
})
app.get('/index', (req, res) => {
res.sendFile(path.join(initial_path, "index.html"));
});
app.get('/auth/steam',
passport.authenticate('steam', { failureRedirect: '/' }),
function(req, res) {
res.redirect('/dashboard');
});
app.get('/auth/steam/return',
passport.authenticate('steam', { failureRedirect: '/' }),
function(req, res) {
res.redirect('/dashboard');
});
app.get('/logout', function(req, res){
req.logout(function(err) {
if (err) { return next(err); }
res.redirect('/main');
});
});
app.get('/faq', (req, res) => {
res.sendFile(path.join(initial_path, "faq.html"));
})
app.listen("3000", () => {
console.log('listening......');
})