|
@@ -4,33 +4,49 @@ import bodyParser from "body-parser";
|
|
|
|
|
|
|
|
const UNDERLYING_URL = "https://goerli.optimism.io";
|
|
const UNDERLYING_URL = "https://goerli.optimism.io";
|
|
|
|
|
|
|
|
|
|
+const IGNORE_METHODS = [
|
|
|
|
|
+ "eth_blockNumber",
|
|
|
|
|
+ "eth_getBalance",
|
|
|
|
|
+ "eth_getBlockByNumber",
|
|
|
|
|
+ "eth_feeHistory",
|
|
|
|
|
+ "eth_call",
|
|
|
|
|
+];
|
|
|
const app = express();
|
|
const app = express();
|
|
|
const port = 8080;
|
|
const port = 8080;
|
|
|
|
|
|
|
|
|
|
+function logRequest(req: any) {}
|
|
|
|
|
+
|
|
|
// Use body-parser to parse JSON request bodies
|
|
// Use body-parser to parse JSON request bodies
|
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.json());
|
|
|
|
|
|
|
|
// Handle POST requests to /
|
|
// Handle POST requests to /
|
|
|
app.post("/", async (req, res) => {
|
|
app.post("/", async (req, res) => {
|
|
|
try {
|
|
try {
|
|
|
- // Get the URL to proxy to from the request body
|
|
|
|
|
- console.log(
|
|
|
|
|
- `[-->] ${req.method} url: ${req.url} path: ${
|
|
|
|
|
- req.path
|
|
|
|
|
- } params: ${JSON.stringify(req.params)}`
|
|
|
|
|
- );
|
|
|
|
|
- console.log(` ${JSON.stringify(req.body)}`);
|
|
|
|
|
-
|
|
|
|
|
if (req.method == "POST") {
|
|
if (req.method == "POST") {
|
|
|
const ethMethod = req.body.method;
|
|
const ethMethod = req.body.method;
|
|
|
|
|
+ const logsEnabled = !IGNORE_METHODS.includes(ethMethod);
|
|
|
|
|
+
|
|
|
|
|
+ if (logsEnabled) {
|
|
|
|
|
+ // Get the URL to proxy to from the request body
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ `[-->] ${req.method} url: ${req.url} path: ${
|
|
|
|
|
+ req.path
|
|
|
|
|
+ } params: ${JSON.stringify(req.params)}`
|
|
|
|
|
+ );
|
|
|
|
|
+ console.log(` ${JSON.stringify(req.body)}`);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (ethMethod === "FOOOOOO") {
|
|
if (ethMethod === "FOOOOOO") {
|
|
|
} else {
|
|
} else {
|
|
|
// default fallback is to proxy the data to the underlying rpc node.
|
|
// default fallback is to proxy the data to the underlying rpc node.
|
|
|
const destUrl = `${UNDERLYING_URL}${req.path}`;
|
|
const destUrl = `${UNDERLYING_URL}${req.path}`;
|
|
|
const response = await axios.post(destUrl, req.body);
|
|
const response = await axios.post(destUrl, req.body);
|
|
|
- console.log(
|
|
|
|
|
- `[<--] ${response.status} ${JSON.stringify(response.data)}`
|
|
|
|
|
- );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (logsEnabled) {
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ `[<--] ${response.status} ${JSON.stringify(response.data)}`
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
res.status(response.status).send(response.data);
|
|
res.status(response.status).send(response.data);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|