forked from cmda-minor-web-cases/so-nuts-2122
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (48 loc) · 1.32 KB
/
app.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
const express = require('express')
const app = express()
const port = process.env.PORT || 5000
const ejs = require('ejs')
const bodyParser = require('body-parser')
const fs = require('file-system')
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args))
require('dotenv').config()
app.set('view engine', 'ejs')
app.set('views', './views/pages')
app.use(express.static('public'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
app.get('/', (req, res) => {
res.render('index')
})
app.get('/intake', (req, res) => {
fetchJson(`https://fhir.mibplatform.nl/api/Questionnaires/2`)
.then(function (jsonData) {
res.render('intake', {
data: jsonData
})
})
})
app.post('/result', (req, res) => {
let userInput;
userInput = JSON.stringify(req.body.inputvalue)
fs.writeFile('resultaten.json', userInput, 'utf8', cb => {
})
res.render('result', {
resultList: JSON.parse(userInput)
})
})
app.get('/day-goals', (req, res) => {
res.render('day-goals')
})
app.get('/dashboard', (req, res) => {
res.render('dashboard')
})
app.listen(port, () => {
console.log(`Listening on port ${port}`)
})
async function fetchJson(url) {
return await fetch(url)
.then((response) => response.json())
.then((body) => body.questions)
.catch((error) => error)
}