-
Notifications
You must be signed in to change notification settings - Fork 0
/
index2.js
47 lines (36 loc) · 1.09 KB
/
index2.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
import { Blockchain } from "./blockchain.js";
import express from "express";
import cors from "cors";
import Cryptr from "cryptr";
import fs from "fs";
const app = express();
const port = 5001;
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const nikahNama = new Blockchain();
const encryption = new Cryptr("nikahNamaKey");
fs.readFile("backup.nk", "utf8", (error, data) => {
if (!error) {
let decrypted = JSON.parse(encryption.decrypt(data));
if (decrypted.length > 0) nikahNama.chain = decrypted;
}
});
const backup = () => {
let encrypted = encryption.encrypt(JSON.stringify(nikahNama.chain));
fs.writeFileSync("backup.nk", encrypted, "utf8", (error, data) => {
if (error) console.log(error);
});
};
app.get("/", (request, response) => {
response.json("hello world");
});
app.get("/blockchain", (request, response) => {
response.json(nikahNama);
});
app.get("/reset", (request, response) => {
response.json("cleared");
});
const server = app.listen(port, () => {
console.log(`Nikahnama Backup listening on port ${port}`);
});