-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (35 loc) · 929 Bytes
/
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
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const PouchDB = require('pouchdb');
const PORT = 9000;
const app = express();
const db = new PouchDB('submissions');
app.use(express.static('public'));
app.use(bodyParser.json());
app.post('/submit', (req, res) => {
console.log('SUBMISSION: '+JSON.stringify(req.body));
const {
email,
responses
} = req.body
const newSubmission = {
_id: email,
responses
};
db.put(newSubmission)
.then(() => {
res.sendStatus(200);
})
.catch(err => {
// TODO: Check for duplicate emails here and report to client
console.error(JSON.stringify(err));
res.sendStatus(500);
})
});
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(PORT, () => {
console.log(`Strive questionnaire server listening on port ${PORT}`);
});