-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (35 loc) · 1.24 KB
/
index.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
let express = require('express')
let spreadsheet = require('./spreadsheet')
let app = express()
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.get('/api', (req, res) => res.send('Hello World'))
app.get('/api/credentials',
(req, res) => spreadsheet.credentials()
.then(obj => res.send(JSON.stringify(obj))));
app.get('/api/leaderboard',
(req, res) => spreadsheet.leaderboard()
.then(obj => res.send(JSON.stringify(obj))));
app.post('/api/signup', (req, res) => {
const newGroup = {
Name: req.body.name,
Password: req.body.password,
};
if (!newGroup.Name || !newGroup.Password) {
res.status(400).json({ msg: 'Please include a name or a password' });
} else {
spreadsheet.save(newGroup).then(x => res.send(JSON.stringify(x)));
}
});
app.post('/api/login', (req, res) => {
const group = {
Name: req.body.name,
Password: req.body.password,
};
if (!group.Name || !group.Password) {
res.status(400).json({ msg: 'Please enter your name and password' });
} else {
spreadsheet.verify(group).then(x => res.send(JSON.stringify(x)));
}
});
app.listen(3000, () => console.log('Server running at Port 3000'))