Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
italolelis committed Oct 11, 2017
1 parent 62eece5 commit aa38d13
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 33 deletions.
7 changes: 6 additions & 1 deletion assets/apis/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"proxy" : {
"preserve_host" : false,
"listen_path" : "/example/*",
"upstream_url" : "http://localhost:9089/hello-world",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://localhost:9089/hello-world"}
]
},
"strip_path" : false,
"append_path" : false,
"methods" : ["GET"]
Expand Down
7 changes: 6 additions & 1 deletion assets/auth/auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"token" : {
"preserve_host" : false,
"listen_path" : "/auth/token",
"upstream_url" : "http://localhost:9088/token",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://localhost:9088/token"}
]
},
"strip_path" : true,
"append_path" : false,
"enable_load_balancing" : false,
Expand Down
2 changes: 1 addition & 1 deletion docs/config/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
|-----------------------|----------------------------------------------------------------------------------------|
| preserve_hosts | Enable the [preserve host](/docs/proxy/preserve_host_property.md) definition |
| listen_path | Defines the [endpoint](/docs/proxy/request_uri.md) that will be exposed in Janus |
| upstream_url | Defines the OAuth provider's [endpoint](/docs/proxy/upstream_url.md) for the request |
| upstreams | Defines the OAuth provider's [endpoints](/docs/proxy/upstreams.md) for the request |
| strip_path | Enable the [strip URI](/docs/proxy/strip_uri_property.md) rule on this proxy |
| enable_load_balancing | Enable load balancing for this proxy |
| methods | Defines which [methods](/docs/proxy/request_http_method.md) are enabled for this proxy |
Expand Down
9 changes: 7 additions & 2 deletions docs/proxy/append_uri_property.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##### The `append_path` property

You might also want to always append the `listen_path` to the upstream `upstream_url`.
You might also want to always append the `listen_path` to the elected upstream target.
To do so, use the `append_path` boolean property by configuring an API like this:

```json
Expand All @@ -9,7 +9,12 @@ To do so, use the `append_path` boolean property by configuring an API like this
"proxy": {
"append_path" : true,
"listen_path": "/service/*",
"upstream_url": "http://my-api.com/example",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com/example"}
]
},
}
}
```
Expand Down
18 changes: 14 additions & 4 deletions docs/proxy/preserve_host_property.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### The `preserve_host` property

When proxying, Janus's default behavior is to set the upstream request's Host header to the hostname of the API's `upstream_url` property. The `preserve_host` field accepts a boolean flag instructing Janus not to do so.
When proxying, Janus's default behavior is to set the upstream request's Host header to the hostname of the API's elected upstream from the`upstreams.targets` property. The `preserve_host` field accepts a boolean flag instructing Janus not to do so.

For example, when the `preserve_host` property is not changed and an API is configured like this:

Expand All @@ -10,7 +10,12 @@ For example, when the `preserve_host` property is not changed and an API is conf
"hosts": ["service.com"],
"proxy": {
"listen_path": "/foo/*",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"methods": ["GET"]
}
}
Expand All @@ -23,7 +28,7 @@ GET / HTTP/1.1
Host: service.com
```

Janus would extract the Host header value from the the hostname of the API's `upstream_url` field, and would send the following request to your upstream service:
Janus would extract the Host header value from the the hostname of the API's elected upstream from the `upstreams.target` field, and would send the following request to your upstream service:

```http
GET / HTTP/1.1
Expand All @@ -38,7 +43,12 @@ However, by explicitly configuring your API with `preserve_host=true`:
"hosts": ["example.com", "service.com"],
"proxy": {
"listen_path": "/foo/*",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"methods": ["GET"],
"preserve_host": true
}
Expand Down
7 changes: 6 additions & 1 deletion docs/proxy/request_http_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ routing via `GET` and `HEAD` HTTP methods:
"proxy": {
"strip_path" : true,
"listen_path": "/hello/*",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"methods": ["GET", "HEAD"]
}
}
Expand Down
7 changes: 6 additions & 1 deletion docs/proxy/request_uri.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ For example, in an API configured like this:
"name": "My API",
"proxy": {
"listen_path": "/hello/*",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"methods": ["GET"],
}
}
Expand Down
14 changes: 12 additions & 2 deletions docs/proxy/routing_capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ Let's go through a few examples. Consider an API configured like this:
"hosts": ["example.com", "service.com"],
"proxy": {
"listen_path": "/foo/*",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"methods": ["GET"]
}
}
Expand Down Expand Up @@ -67,7 +72,12 @@ Now that we understand how the hosts, uris, and methods properties work together
"hosts": ["example.com", "service.com"],
"proxy": {
"listen_path": "/foo/*",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"insecure_skip_verify": true,
"methods": ["GET"]
}
Expand Down
14 changes: 12 additions & 2 deletions docs/proxy/routing_priorities.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@ For example, two APIs are configured like this:
"name": "API 1",
"proxy": {
"listen_path": "/",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"hosts": ["example.com"]
}
},
{
"name": "API 2",
"proxy": {
"listen_path": "/",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"hosts": ["example.com"],
"methods": ["POST"]
}
Expand Down
7 changes: 6 additions & 1 deletion docs/proxy/strip_uri_property.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ property by configuring an API like this:
"proxy": {
"strip_path" : true,
"listen_path": "/service/*",
"upstream_url": "http://my-api.com",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://my-api.com"}
]
},
"methods": ["GET"]
}
}
Expand Down
8 changes: 7 additions & 1 deletion docs/quick_start/add_auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ Lets create a file with the oAuth2 configuration called `auth.json`:
"oauth_endpoints" : {
"token" : {
"listen_path" : "/auth/token",
"upstream_url" : "http://auth-service:8080/token",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://auth-service1:8080/token"},
{"target": "http://auth-service2:8080/token"},
]
},
"strip_path" : true,
"append_path" : false,
"methods" : ["POST"]
Expand Down
9 changes: 7 additions & 2 deletions docs/quick_start/add_endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ Create an `example.json` file containing your endpoint configuration:
"active" : true,
"proxy" : {
"listen_path" : "/example/*",
"upstream_url" : "http://www.mocky.io/v2/595625d22900008702cd71e8",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://www.mocky.io/v2/595625d22900008702cd71e8"}
]
},
"methods" : ["GET"]
}
}
Expand Down Expand Up @@ -54,6 +59,6 @@ http -v GET http://localhost:8080/example
curl -vX "GET" http://localhost:8080/example
{%- endcodetabs %}

A successful response means Janus is now forwarding requests made to `http://localhost:8000` to the `upstream_url` we configured in step #1, and is forwarding the response back to us.
A successful response means Janus is now forwarding requests made to `http://localhost:8000` to the elected upstream target (chosen by the load balancer) wex configured in step #1, and is forwarding the response back to us.

[Next](add_plugins.md) we'll learn how to add plugins to our endpoint.
2 changes: 1 addition & 1 deletion docs/quick_start/file_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you access `http://localhost:8080/example` you should something like:
```

A successful response means Janus is now forwarding requests made to
`http://localhost:8080` to the `upstream_url` we configured in step #1,
`http://localhost:8080` to the elected upstream target (chosen by the load balancer) we configured in step #1,
and is forwarding the response back to us.

## Understanding the directory structure
Expand Down
7 changes: 6 additions & 1 deletion examples/front-proxy-auth/apis/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"proxy" : {
"preserve_host" : false,
"listen_path" : "/example/*",
"upstream_url" : "http://service1:8080/",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://service1:8080/"}
]
},
"strip_path" : false,
"append_path" : false,
"methods" : ["GET"]
Expand Down
7 changes: 6 additions & 1 deletion examples/front-proxy-auth/auth/auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"token" : {
"preserve_host" : false,
"listen_path" : "/auth/token",
"upstream_url" : "http://auth-service:8080/token",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://auth-service:8080/token"}
]
},
"strip_path" : true,
"append_path" : false,
"enable_load_balancing" : false,
Expand Down
7 changes: 6 additions & 1 deletion examples/front-proxy-cluster/apis/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"proxy" : {
"preserve_host" : false,
"listen_path" : "/example/*",
"upstream_url" : "http://service1:8080/",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://service1:8080/"}
]
},
"strip_path" : false,
"append_path" : false,
"methods" : ["GET"]
Expand Down
7 changes: 6 additions & 1 deletion examples/front-proxy-mongo/apis/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"proxy" : {
"preserve_host" : false,
"listen_path" : "/example/*",
"upstream_url" : "http://service1:8080/",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://service1:8080/"}
]
},
"strip_path" : false,
"append_path" : false,
"methods" : ["GET"]
Expand Down
7 changes: 6 additions & 1 deletion examples/front-proxy/apis/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"proxy" : {
"preserve_host" : false,
"listen_path" : "/example/*",
"upstream_url" : "http://service1:8080/",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://service1:8080/"}
]
},
"strip_path" : false,
"append_path" : false,
"methods" : ["GET"]
Expand Down
7 changes: 6 additions & 1 deletion examples/janus-tls/apis/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"proxy" : {
"preserve_host" : false,
"listen_path" : "/example/*",
"upstream_url" : "http://service1:8080/",
"upstreams" : {
"balancing": "roundrobin",
"targets": [
{"target": "http://service1:8080/"}
]
},
"strip_path" : false,
"append_path" : false,
"methods" : ["GET"]
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/oauth2/mongodb_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r *MongoRepository) FindByTokenURL(url url.URL) (*OAuth, error) {
session, coll := r.getSession()
defer session.Close()

err := coll.Find(bson.M{"oauth_endpoints.token.upstream_url": url.String()}).One(&result)
err := coll.Find(bson.M{"oauth_endpoints.token.upstreams.targets.target": url.String()}).One(&result)

return result, err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/proxy/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func NewDefinition() *Definition {
return &Definition{
Methods: make([]string, 0),
Hosts: make([]string, 0),
Upstreams: &Upstreams{
Targets: make([]*Target, 0),
},
}
}

Expand Down
9 changes: 3 additions & 6 deletions pkg/proxy/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ func TestInvalidTargetURLValidation(t *testing.T) {
}

func TestRouteToJSON(t *testing.T) {
definition := Definition{
Methods: make([]string, 0),
Hosts: make([]string, 0),
}
route := NewRoute(&definition)
definition := NewDefinition()
route := NewRoute(definition)
json, err := route.JSONMarshal()
assert.NoError(t, err)
assert.JSONEq(
t,
`{"proxy": {"insecure_skip_verify": false, "append_path":false, "enable_load_balancing":false, "methods":[], "hosts":[], "preserve_host":false, "listen_path":"", "upstream_url":"", "strip_path":false}}`,
`{"proxy": {"insecure_skip_verify": false, "append_path":false, "enable_load_balancing":false, "methods":[], "hosts":[], "preserve_host":false, "listen_path":"", "upstream_url":"", "strip_path":false, "upstreams": {"balancing": "", "targets": [] }}}`,
string(json),
)
}
Expand Down

0 comments on commit aa38d13

Please sign in to comment.