-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (25 loc) · 838 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
const express = require('express');
const app = express();
const data = require('./data.json');
const PORT = process.env.PORT || 8000;
app.use(express.static(__dirname + '/public'));
app.use(express.json());
app.get('/', (req,res)=>{
res.sendFile(__dirname + './public/index.html');
});
app.get('/question:id', (req, res)=>{
let id = req.params.id;
res.json({"question": data.questions[id].question, "id": data.questions[id].id, "images": data.questions[id].images});
});
app.post('/answer:id', (req,res)=>{
let id = req.params.id;
let answer = req.body.answer;
if(data.questions[id].answer == answer){
res.json({success: true, nextURL: data.questions[id].nextURL});
}else{
res.json({success: false});
}
});
app.listen(PORT, ()=>{
console.log(`Listening on port ${PORT}`);
})