This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
forked from JunWonOh/Office-Hours-MLH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (53 loc) · 1.65 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
require('dotenv').config();
// imports
const port = process.env.PORT || 3001;
const cors = require('cors');
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const { auth, requiresAuth } = require('express-openid-connect');
app.set('view engine', 'ejs');
app.use(express.static("public"));
var server = app.listen(port, function() {
console.log(`Server initialized on port ${port}`);
console.log("From server.js");
});
const socket = require('socket.io');
const io = socket(server, {
cors: {
origin: "http://localhost:3001",
methods: ["GET", "POST"],
credentials: true,
}
});
io.sockets.on('connection', function(socket) {
console.log(`connected at: ${socket.id}`);
socket.on('mouse', function(data) {
socket.broadcast.emit('mouse', data);
console.log(data);
});
});
app.use(
auth({
//every route does not need authentication
authRequired: false,
auth0Logout: true,
issuerBaseURL: process.env.ISSUER_BASE_URL,
baseURL: process.env.BASE_URL,
clientID: process.env.CLIENT_ID,
secret: process.env.SECRET
})
);
app.get('/', (req, res) => {
//oidc = open id connect
req.oidc.isAuthenticated() ? res.render("auth-home") : res.render("home")
// res.send(req.oidc.isAuthenticated() ? 'Logged in' : 'Logged out');
});
app.get('/profile', requiresAuth(), (req, res) => {
//how to obtain user data:
//given_name, family_name, nickname, name, picture, email
res.send(JSON.stringify(req.oidc.user));
});
app.get('/board', requiresAuth(), (req, res) => {
res.render("whiteboard");
});