-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (45 loc) · 1.62 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
const express = require('express');
const bodyParser = require('body-parser');
const googleSheets = require('gsa-sheets');
const key = require('./privateSettings.json');
// TODO(you): Change the value of this string to the spreadsheet id for your
// GSA spreadsheet. See HW5 spec for more information.
const SPREADSHEET_ID = '__YOUR__SPREADSHEET__ID__HERE__';
const app = express();
const jsonParser = bodyParser.json();
const sheet = googleSheets(key.client_email, key.private_key, SPREADSHEET_ID);
app.use(express.static('public'));
async function onGet(req, res) {
const result = await sheet.getRows();
const rows = result.rows;
console.log(rows);
// TODO(you): Finish onGet.
res.json( { status: 'unimplemented'} );
}
app.get('/api', onGet);
async function onPost(req, res) {
const messageBody = req.body;
// TODO(you): Implement onPost.
res.json( { status: 'unimplemented'} );
}
app.post('/api', jsonParser, onPost);
async function onPatch(req, res) {
const column = req.params.column;
const value = req.params.value;
const messageBody = req.body;
// TODO(you): Implement onPatch.
res.json( { status: 'unimplemented'} );
}
app.patch('/api/:column/:value', jsonParser, onPatch);
async function onDelete(req, res) {
const column = req.params.column;
const value = req.params.value;
// TODO(you): Implement onDelete.
res.json( { status: 'unimplemented'} );
}
app.delete('/api/:column/:value', onDelete);
// Please don't change this; this is needed to deploy on Heroku.
const port = process.env.PORT || 3000;
app.listen(port, function () {
console.log(`Server listening on port ${port}!`);
});