Skip to content

Commit

Permalink
Api basepath share (#471)
Browse files Browse the repository at this point in the history
* Allow `api` blocks sharing the same `base_path`

* Docs
  • Loading branch information
afflerbach authored Apr 5, 2022
1 parent a4d839c commit 00f9c24
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Unreleased changes are available as `avenga/couper:edge` container.

* **Fixed**
* missing error handling while loading a given `ca_file` ([#460](https://github.com/avenga/couper/pull/460))
* allow [`api` blocks](./docs/REFERENCE.md#api-block) sharing the same `base_path` ([#471](https://github.com/avenga/couper/pull/471))


---

Expand Down
23 changes: 22 additions & 1 deletion config/configload/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestLabels(t *testing.T) {
"",
},
{
"multiple anonymous api blocks",
"multiple anonymous api blocks, different base_path",
`server "test" {
api {
base_path = "/foo"
Expand All @@ -125,6 +125,27 @@ func TestLabels(t *testing.T) {
}`,
"",
},
{
"multiple anonymous api blocks (sharing base_path)",
`server "test" {
api {}
api {}
}`,
"",
},
{
"api blocks sharing base_path",
`server "test" {
api {
base_path = "/foo"
}
api {
base_path = "/foo"
}
}`,
"",
},

{
"mixed labelled api blocks",
`server "test" {
Expand Down
4 changes: 0 additions & 4 deletions config/runtime/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ func newEndpointMap(srvConf *config.Server, serverOptions *server.Options) (endp

isAPIBasePathUniqueToFilesAndSPA := basePath != filesBasePath && basePath != spaBasePath

if _, ok := apiBasePaths[basePath]; ok {
return nil, fmt.Errorf("API paths must be unique")
}

apiBasePaths[basePath] = struct{}{}

for _, epConf := range apiConf.Endpoints {
Expand Down
2 changes: 1 addition & 1 deletion docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ as json error with an error body payload. This can be customized via `error_file

| Attribute(s) | Type |Default|Description|Characteristic(s)| Example|
| :------------------------------ | :--------------- | :--------------- | :--------------- | :--------------- | :--------------- |
|`base_path`|string|-|Configures the path prefix for all requests.|⚠ Must be unique if multiple `api` blocks are defined.| `base_path = "/v1"`|
|`base_path`|string|-|Configures the path prefix for all requests.|| `base_path = "/v1"`|
| `error_file` |string|-|Location of the error file template.|-|`error_file = "./my_error_body.json"`|
| `access_control` |list|-|Sets predefined [Access Control](#access-control) for `api` block context.|⚠ Inherited by nested blocks.| `access_control = ["foo"]`|
| `allowed_methods` | tuple of string | `["*"]` == `["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]` | Sets allowed methods as _default_ for all contained endpoints. Requests with a method that is not allowed result in an error response with a `405 Method Not Allowed` status. | The default value `*` can be combined with additional methods. Methods are matched case-insensitively. `Access-Control-Allow-Methods` is only sent in response to a [CORS](#cors-block) preflight request, if the method requested by `Access-Control-Request-Method` is an allowed method. | `allowed_methods = ["GET", "POST"]` or `allowed_methods = ["*", "BREW"]` |
Expand Down

0 comments on commit 00f9c24

Please sign in to comment.