Skip to content

Commit de20eca

Browse files
authored
Merge pull request #76 from willingc/refresh-docs
Edit documentation for install and usage
2 parents f54c6a4 + 57a481e commit de20eca

File tree

1 file changed

+66
-23
lines changed

1 file changed

+66
-23
lines changed

README.md

+66-23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
**[Install](#install)** |
2+
**[Using configurable-http-proxy](#using-configurable-http-proxy)** |
3+
**[Using the REST API](#using-the-rest-api)** |
4+
**[Custom error pages](#custom-error-pages)** |
5+
**[Host-based routing](#host-based-routing)**
6+
17
# configurable-http-proxy
28

39
[![Build Status](https://travis-ci.org/jupyterhub/configurable-http-proxy.svg?branch=master)](https://travis-ci.org/jupyterhub/configurable-http-proxy)
@@ -19,11 +25,14 @@ node-http-proxy to provide this functionality to JupyterHub.
1925

2026
## Install
2127

22-
To install `configurable-http-proxy` globally using the npm package manager:
28+
Prerequisite: [Node.js](https://nodejs.org/en/download/)
29+
30+
To install globally from the `configurable-http-proxy` package release
31+
using the npm package manager:
2332

2433
npm install -g configurable-http-proxy
2534

26-
To install from source found in this GitHub repo:
35+
To install from the source code found in this GitHub repo:
2736

2837
git clone https://github.com/jupyterhub/configurable-http-proxy.git
2938
cd configurable-http-proxy
@@ -41,10 +50,13 @@ The configurable proxy runs two HTTP(S) servers:
4150
localhost by default. The REST API uses token authorization, set by the
4251
`CONFIGPROXY_AUTH_TOKEN` environment variable.
4352

44-
When you start the proxy, you can set a default target to be used when no
53+
### Setting a default target
54+
55+
When you start the proxy from the command line, you can set a
56+
default target (`--default-target` option) to be used when no
4557
matching route is found in the proxy table:
4658

47-
$ configurable-http-proxy --default-target=http://localhost:8888
59+
configurable-http-proxy --default-target=http://localhost:8888
4860

4961
### Command-line options
5062

@@ -57,6 +69,7 @@ matching route is found in the proxy table:
5769
-V, --version output the version number
5870
--ip <ip-address> Public-facing IP of the proxy
5971
--port <n> (defaults to 8000) Public-facing port of the proxy
72+
6073
--ssl-key <keyfile> SSL key to use, if any
6174
--ssl-cert <certfile> SSL certificate to use, if any
6275
--ssl-ca <ca-file> SSL certificate authority, if any
@@ -66,13 +79,15 @@ matching route is found in the proxy table:
6679
--ssl-ciphers <ciphers> `:`-separated ssl cipher list. Default excludes RC4
6780
--ssl-allow-rc4 Allow RC4 cipher for SSL (disabled by default)
6881
--ssl-dhparam <dhparam-file> SSL Diffie-Helman Parameters pem file, if any
82+
6983
--api-ip <ip> Inward-facing IP for API requests
7084
--api-port <n> Inward-facing port for API requests (defaults to --port=value+1)
7185
--api-ssl-key <keyfile> SSL key to use, if any, for API requests
7286
--api-ssl-cert <certfile> SSL certificate to use, if any, for API requests
7387
--api-ssl-ca <ca-file> SSL certificate authority, if any, for API requests
7488
--api-ssl-request-cert Request SSL certs to authenticate clients for API requests
7589
--api-ssl-reject-unauthorized Reject unauthorized SSL connections (only meaningful if --api-ssl-request-cert is given)
90+
7691
--default-target <host> Default proxy target (proto://host[:port])
7792
--error-target <host> Alternate server for handling proxy errors (proto://host[:port])
7893
--error-path <path> Alternate server for handling proxy errors (proto://host[:port])
@@ -89,19 +104,29 @@ matching route is found in the proxy table:
89104
--log-level <loglevel> Log level (debug, info, warn, error)
90105
```
91106

107+
92108
## Using the REST API
93109

94-
The REST API is authenticated via a token in the `Authorization` header.
95-
The API is served under the `/api/routes` base URL. For example:
110+
The configurable-http-proxy API is documented and available at the
111+
interactive swagger site, [petstore](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyterhub/configurable-http-proxy/master/doc/rest-api.yml#/default)
112+
or as a [swagger specification file in this repo](https://github.com/jupyterhub/configurable-http-proxy/blob/master/doc/rest-api.yml).
113+
114+
### Authenticating via passing a token
96115

97-
$> curl -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" http://localhost:8001/api/routes
116+
The REST API is authenticated via passing a token in the `Authorization` header.
117+
The API is served under the `/api/routes` base URL. For example, execute
118+
this `curl` command in the terminal to authenticate and retrieve the
119+
current routing table:
98120

121+
curl -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" http://localhost:8001/api/routes
99122

100123
### Getting the current routing table
101124

125+
**Request**
126+
102127
GET /api/routes[?inactive_since=ISO8601-timestamp]
103128

104-
Returns a JSON dictionary of the current routing table.
129+
The GET request returns a JSON dictionary of the current routing table.
105130

106131
This JSON dictionary *excludes* the default route. If the `inactive_since` URL
107132
parameter is given as an [ISO8601](http://en.wikipedia.org/wiki/ISO_8601)
@@ -110,8 +135,11 @@ will be returned.
110135

111136
**Response**
112137

138+
Status code:
139+
113140
status: 200 OK
114141

142+
Returned JSON dictionary of current routing table:
115143

116144
```json
117145
{
@@ -129,69 +157,84 @@ will be returned.
129157
The `last_activity` timestamp is updated whenever the proxy passes data to
130158
or from the proxy target.
131159

132-
133160
### Adding new routes
134161

135162
POST requests create new routes. The body of the request should be a JSON
136163
dictionary with at least one key: `target`, the target host to be proxied.
137164

165+
**Request**
166+
138167
POST /api/routes/[:path]
139168

140-
**Input**
169+
*Input - request body*
141170

142171
`target`: The host URL
143172

144173
**Response**
145174

146175
status: 201 Created
147176

148-
Any request to `/path/prefix` on the proxy's public interface will be proxied
149-
to `target`.
177+
After adding the new route, any request to `/path/prefix` on the proxy's
178+
public interface will be proxied to `target`.
150179

151180
### Deleting routes
152181

182+
**Request**
183+
153184
DELETE /api/routes/[:path]
154185

155186
**Response**
156187

157188
status: 204 No Content
158189

190+
Removes a route from the proxy's routing table.
191+
192+
159193
## Custom error pages
160194

161195
With version 0.5, configurable-host-proxy (CHP) adds two ways to provide
162196
custom error pages when the proxy encounters an error, and has no proxy target
163-
to handle a request. There are two typical errors that CHP can hit:
197+
to handle a request. There are two typical errors that CHP can hit, along
198+
with their status code:
164199

165200
- 404: a client has requested a URL for which there is no routing target.
166-
This is impossible if a default target has been specified.
201+
This can be prevented if a `default target` is specified when starting
202+
the configurable-http-proxy.
167203

168204
- 503: a route exists, but the upstream server isn't responding.
169205
This is more common, and can be due to any number of reasons,
170206
including the target service having died or not finished starting.
171207

172208
### error-path
173209

174-
If you specify `--error-path /usr/share/chp-errors`, then when a proxy error
175-
occurs, CHP will look in `/usr/share/chp-errors/CODE.html` for an html page
176-
to serve, e.g. `404.html` or `503.html`.
210+
If you specify an error path `--error-path /usr/share/chp-errors` when
211+
starting the CHP:
212+
213+
configurable-http-proxy --error-path /usr/share/chp-errors
214+
215+
then when a proxy error occurs, CHP will look in
216+
`/usr/share/chp-errors/<CODE>.html` (where CODE is the status code number)
217+
for an html page to serve, e.g. `404.html` or `503.html`.
177218

178219
If no file exists for the error code, `error.html` file will be used.
179-
If you use this approach, make sure you have created `error.html`.
220+
If you specify an error path, make sure you also create `error.html`.
180221

181222
### error-target
182223

224+
When starting the CHP, you can pass a command line option for `--error-target`.
183225
If you specify `--error-target http://localhost:1234`,
184-
then when the proxy encounters an error, it will make a GET request to this
185-
server, with URL `/CODE`, and the URL of the failing request escaped in a URL
186-
parameter, e.g.:
226+
then when the proxy encounters an error, it will make a GET request to
227+
this server, with URL `/CODE`, and the URL of the failing request
228+
escaped in a URL parameter, e.g.:
187229

188230
GET /404?url=%2Fescaped%2Fpath
189231

190232

191233
## Host-based routing
192234

193-
If `--host-routing` is given, the proxy will pick a target based on the host
194-
of the incoming request, instead of the URL prefix.
235+
If the CHP is started with the `--host-routing` option, the proxy will
236+
pick a target based on the host of the incoming request, instead of the
237+
URL prefix.
195238

196239
The API when using host-based routes is the same as if the hostname were the
197240
first part of the URL path, e.g.:

0 commit comments

Comments
 (0)