-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
35 lines (30 loc) · 849 Bytes
/
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
const express = require('express')
const bodyParser = require('body-parser');
const fs = require('fs')
const app = express()
const port = 3000
app.use(bodyParser.raw({limit: '200mb'}))
app.use(bodyParser.text({limit: '200mb'}))
app.get('/ok', (req, res) => {
res.send('Hello World!')
})
app.get('/load/:user', (req, res) => {
const user = req.params.user
try {
const binary = fs.readFileSync(`./save_files/${user}`);
console.log(binary)
res.send(binary)
}
catch (e) {
res.send()
}
})
app.post('/save/:user', (req, res) => {
const user = req.params.user
console.log(req.body)
const binary = fs.writeFileSync(`./save_files/${user}`, req.body)
res.send('Saved successfully')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})