Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

31 changes: 25 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
{
"env": {
"node": true
},
"extends": [
"bloq"
]
"extends": ["bloq", "bloq/node", "prettier"],
"ignorePatterns": ["coverage"],
"overrides": [
{
"files": ["bin/*.js"],
"rules": {
"no-console": "off"
}
},
{
"extends": ["bloq/mocha", "prettier"],
"files": ["*.spec.js"],
"rules": {
"promise/catch-or-return": [
"error",
{
"allowFinally": true
}
]
}
}
],
"rules": {
"jsdoc/require-returns": "off"
}
}
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @gabmontes
15 changes: 15 additions & 0 deletions .github/workflows/js-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: JS Checks

on:
pull_request:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
js-checks:
uses: bloq/actions/.github/workflows/js-checks.yml@v1
with:
node-versions: '["18", "20", "22"]'
14 changes: 14 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: NPM Publish

on:
release:
types:
- published

jobs:
npm-publish:
permissions:
contents: read
id-token: write
secrets: inherit
uses: bloq/actions/.github/workflows/npm-publish.yml@v1
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"semi": false,
"singleQuote": true,
"trailingComma": "none"
}
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
# http-json-proxy

[![Build Status](https://travis-ci.org/bloq/http-json-proxy.svg?branch=master)](https://travis-ci.org/bloq/http-json-proxy)
[![bitHound Overall Score](https://www.bithound.io/github/bloq/http-json-proxy/badges/score.svg)](https://www.bithound.io/github/bloq/http-json-proxy)
[![bitHound Dependencies](https://www.bithound.io/github/bloq/http-json-proxy/badges/dependencies.svg)](https://www.bithound.io/github/bloq/http-json-proxy/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/bloq/http-json-proxy/badges/code.svg)](https://www.bithound.io/github/bloq/http-json-proxy)

Simple HTTP JSON proxy.

This proxy can be used as a middleman in between a HTTP JSON API server and a client to monitor the requests, responses and even modify on the fly any of those.

## Installation

```bash
$ npm install --global http-json-proxy
```sh
npm install --global http-json-proxy
```

## Usage

The following command will spin up a proxy server that will forward all requests to a locally installed Ethereum node and will log to console each JSON RPC call with the corresponding response:

```
```console
$ http-json-proxy -p 18545 -t http://localhost:8545
Proxy for http://localhost:8545 listening on port 18545
```

Then, each call will be logged as follows:

```
```text
--> POST / {"jsonrpc":"2.0","id":3,"method":"eth_gasPrice","params":[]}
<-- {"jsonrpc":"2.0","result":"0x2e90edd000","id":3}
```

### Options

```
```console
$ http-json-proxy
Start a HTTP JSON proxy server.

Expand Down
6 changes: 0 additions & 6 deletions bin/.eslintrc.json

This file was deleted.

20 changes: 10 additions & 10 deletions bin/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const argv = yargs
})
.options('target', {
alias: 't',
describe: 'the proxied API server URL',
demandOption: true,
describe: 'the proxied API server URL',
type: 'string'
})
.options('pretty-print', {
Expand All @@ -27,26 +27,26 @@ const argv = yargs
.help()
.parse()

const { port, target, prettyPrint } = argv
const { port, prettyPrint, target } = argv

const formatJson = object =>
colorize(prettyPrint ? JSON.stringify(object, null, 2) : object)

const proxy = createProxy({
port,
target,
onReq (req) {
onErr(err) {
console.warn('<-- ERROR', err.message)
return err
},
onReq(req) {
console.log('-->', req.method, req.url, formatJson(req.body))
return req
},
onRes (body) {
onRes(body) {
console.log('<--', formatJson(body))
return body
},
onErr (err) {
console.warn('<-- ERROR', err.message)
return err
}
port,
target
})

proxy.on('listening', function () {
Expand Down
Loading
Loading