-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (27 loc) · 784 Bytes
/
server.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
const express = require("express");
const path = require("path");
const fs = require("fs");
const app = express();
const PORT = 8000;
let bodyParser = require('body-parser') ;
app.use(bodyParser.text());
app.use(express.static("build"));
app.post("/load/:json_file", (req, res) => {
let data = fs.readFileSync(
path.join(__dirname, "/data", req.params.json_file)
);
res.send(data);
});
// save data to data.json
app.post("/save/:json_file", (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
let data = req.body;
fs.writeFileSync(
path.join(__dirname, "/data", req.params.json_file),
data
);
res.send(data);
});
app.listen(PORT, function () {
console.log("Express server listening on port ", PORT);
});