# @advanced-rest-client/arc-proxy

> A web service to proxy ARC requests through it.

Latest version **0.1.0** (published 2021-11-09) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @advanced-rest-client/arc-proxy
pnpm add @advanced-rest-client/arc-proxy
yarn add @advanced-rest-client/arc-proxy
bun add @advanced-rest-client/arc-proxy
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-11-09 |
| First published | 2021-11-09 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 32.9 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Pawel Uchida-Psztyc |
| Maintainers | jarrodek, twoplustwoone, lbauret, carowright |

## Links

- npm: https://www.npmjs.com/package/@advanced-rest-client/arc-proxy
- Repository: https://github.com/advanced-rest-client/arc-proxy
- Homepage: https://github.com/advanced-rest-client/arc-proxy#readme
- Issues: https://github.com/advanced-rest-client/arc-proxy/issues
- npm.io page: https://npm.io/package/@advanced-rest-client/arc-proxy

## Dependencies (7)

- [esm](https://npm.io/package/esm.md) ^3.2.25
- [koa](https://npm.io/package/koa.md) ^2.13.4
- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [@koa/cors](https://npm.io/package/@koa/cors.md) ^3.1.0
- [@koa/router](https://npm.io/package/@koa/router.md) ^10.1.1
- [@advanced-rest-client/events](https://npm.io/package/@advanced-rest-client/events.md) ^0.2.29
- [@advanced-rest-client/electron](https://npm.io/package/@advanced-rest-client/electron.md) ^0.1.0

## Recent versions

- 0.1.0 (latest) — 2021-11-09

## README

# ARC proxy server

A node web server that runs on [Koa](https://koajs.com/) that provides an API to proxy HTTP request.

The intended use is to proxy ARC/API Console requests from a web browser without CORS restrictions.

## Usage

### Installation

```sh
npm i @advanced-rest-client/arc-proxy
```

### Running the server

```javascript
import Server from '@advanced-rest-client/arc-proxy';

(async () => {
  const httpPort = 8080;
  const sslPort = 8081;

  const sslOptions = {
    key: fs.readFileSync('key.pem'),
    cert: fs.readFileSync('cert.pem')
  };
  
  const srv = new Server();
  srv.setupRoutes('/api/v1'); // optional prefix for the API routes.

  await srv.startHttp(httpPort);
  await srv.startSsl(sslOptions, httpPort);

  // when ready...
  await srv.stopHttp(); 
  await srv.stopSsl(); 
})();
```

## API routes

See the API spec in `spec/` folder for more details.

Notes:

- Examples assume no API prefix and port 8080
- Example responses are formatted for readability

### Proxying a request

The proxy server uses the ARC request object definition for the request.

```http
POST /proxy HTTP/1.1
Host: localhost:8080
Content-Type: application/json
content-length: ...

{
  "request": {
    "url": "https://httpbin.org/get",
    "method": "GET",
    "headers": "x-test: true"
  },
  "config": {
    "followRedirects": false
  }
}
```

#### Proxy response

```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: ...
Date: Sat, 06 Nov 2021 00:01:15 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{
  "response": {
    "status": 200,
    "statusText": "OK",
    "headers: "...",
    "payload": {
      "type": "Buffer",
      "data": [102, 168, ...]
    },
    "timings": {
      "connect": 10,
      "receive": 2,
      "send": 15,
      "wait": 2,
      "blocked": 0
      "dns": 4
      "ssl": 12
    },
    "loadingTime": 123,
    "redirects": [],
    "size": {
      "request": 1234,
      "response": 5678
    }
  },
  "transport": {
    "httpMessage": {
      "type": "Buffer",
      "data": [102, 168, ...]
    },
    "startTime": 123456789,
    "endTime": 123456789
  }
}
```

## Development

```sh
git clone https://github.com/advanced-rest-client/arc-proxy
cd arc-proxy
npm install
```

### Running the tests

```sh
npm test
```

## Credits and license

This library has been created by Pawel Uchida-Psztyc on his own free time. It is licensed under Apache 2 license.

---
_Source: https://npm.io/package/@advanced-rest-client/arc-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
