-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
59 lines (51 loc) · 1.31 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
const express = require('express')
const { reactive, effect } = require('@vue/reactivity')
const {
tweet,
yeet,
initCreateSpreadsheet,
whiteHeat,
somethingBittersweet
} = require('./effects.js')
const database = require('./database.js')
effect(tweet)
effect(yeet)
const app = express()
const port = 3000
app.use(express.json())
app.get('/', (req, res) => res.send('Database contents: ' + JSON.stringify(database, null, 2)))
app.post('/users', (req, res) => {
database.push(req.body)
res.sendStatus(201)
})
app.delete('/users/:name', (req, res) => {
database.forEach((record) => {
if (record.name === req.params.name) {
record.yeet = true
}
})
res.sendStatus(200)
})
app.patch('/users/:name', (req, res) => {
database.forEach((record) => {
if (record.name === req.params.name) {
for (let [k, v] of Object.entries(req.body)) {
record[k] = v
}
}
})
res.sendStatus(200)
})
app.post('/superusers', (req, res) => {
const record = reactive(req.body)
effect(initCreateSpreadsheet(record))
database.push(record)
res.sendStatus(201)
})
app.delete('/purge', (req, res) => {
effect(whiteHeat)
effect(somethingBittersweet)
database.length = 0
res.sendStatus(200)
})
app.listen(port, () => console.log(`Fired up that sweet Vue backend on port ${port}!`))