-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (59 loc) · 1.15 KB
/
index.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
60
61
62
63
64
const decode = require("./decode.js");
const encode = require("./encode.js");
const decodeSchema = {
body: {
type: "object",
required: [
"html"
],
properties: {
html: { type: "string" },
options: { type: "object" }
}}
};
const encodeSchema = {
body: {
type: "object",
required: [
"text"
],
properties: {
text: { type: "string" },
options: { type: "object" }
}}
};
async function bzmbHe(fastify, options) {
fastify.post(
"/bzmb-he-decode",
{ schema: decodeSchema },
(req, res) => {
try {
const result = decode(req.body.html, req.body.options);
res
.code(200)
.send(result);
} catch (error) {
res
.code(500)
.send(error);
}
}
);
fastify.post(
"/bzmb-he-encode",
{ schema: encodeSchema },
(req, res) => {
try {
const result = encode(req.body.text, req.body.options);
res
.code(200)
.send(result);
} catch (error) {
res
.code(500)
.send(error);
}
}
);
}
module.exports = { microbond: bzmbHe };