-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (37 loc) · 1.21 KB
/
server.js
File metadata and controls
49 lines (37 loc) · 1.21 KB
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
const express = require('express')
const app = express()
const cors = require('cors')
app.use(cors({
origin:"http://localhost:3000"
}))
app.use(express.json())
app.use(express.urlencoded({extend: false}))
app.post("/api/addFavorite",async (req,res) =>{
const commit = req.body
const fs = require('fs');
fs.writeFileSync('favorite.txt',JSON.stringify(commit),(err) => {
if (err)
JSON.stringify({err : err})
});
const contents = fs.readFileSync('favorite.txt', {encoding: 'base64'});
res.end(JSON.stringify({content : contents}))
})
app.post("/api/decodeFavorite",async (req,res) =>{
const base64Data = req.body
const fs = require('fs');
fs.writeFileSync("out.txt", base64Data.content, 'base64', function(err) {
if(err){
res.errored(JSON.stringify(err));
}
});
fs.readFile('out.txt', 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
res.end(JSON.stringify({data:data,
globalSha:base64Data.sha,
}));
});
})
app.listen(5000,() => {console.log("Server started on port 5000")})