-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
47 lines (40 loc) · 1.26 KB
/
index.ts
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
const mainnet = "https://fullnode.mainnet.sui.io:443";
import express from "express";
import { createProxyMiddleware } from "http-proxy-middleware";
import { type IRequestBody } from "./core/parse";
import { safeJsonParse } from "./utils";
import { TransactionGuard } from "./core";
const app = express();
const port = 3000;
app.use(
"/",
createProxyMiddleware({
target: "https://fullnode.mainnet.sui.io",
changeOrigin: true,
secure:false,
on: {
proxyReq: (proxyReq, req, res) => {
/* handle proxyReq */
let data: Uint8Array[] = [];
let body = ''
req.on("data", (chunk) => {
data.push(chunk); // Accumulate the received data chunks into a Uint8Array array
});
req.on("end", () => {
body = Buffer.concat(data).toString(); // Convert the accumulated data chunks into a string
TransactionGuard(body);
});
proxyReq.setHeader('Access-Control-Allow-Origin','*');
},
proxyRes: (proxyRes, req, res) => {
/* handle proxyRes */
proxyRes.headers["access-control-allow-headers"] = "*";
},
error: (err, req, res) => {
/* handle error */
console.log(err);
},
},
})
);
app.listen(port);