Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 45d437f

Browse files
committed
Merge branch 'master' of github.com:serverless/serverless-openwhisk
2 parents e02f227 + b3b40ef commit 45d437f

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ functions:
777777
HTTP event configuration also supports using explicit parameters.
778778

779779
- `method` - HTTP method (mandatory).
780+
- `basepath` - base path of the API in which the event is added (optional, defaults to service name)
780781
- `path` - URI path for API gateway (mandatory).
781782
- `resp` - controls [web action content type](https://github.com/apache/incubator-openwhisk/blob/master/docs/webactions.md#additional-features), values include: `json`, `html`, `http`, `svg`or `text` (optional, defaults to `json`).
782783

@@ -787,6 +788,7 @@ functions:
787788
events:
788789
- http:
789790
method: GET
791+
basepath: /mybasepath
790792
path: /api/http
791793
resp: http
792794
```

compile/apigw/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ definitions.
1010

1111
It loops over all functions which are defined in `serverless.yaml` looking for
1212
the defined events. For each `http` event defined for the function, the
13-
corresponding API gateway endpoint definitoin will be created.
13+
corresponding API gateway endpoint definition will be created.
1414

1515
## Examples
1616

@@ -37,6 +37,7 @@ functions:
3737
events:
3838
- http:
3939
method: GET
40+
basepath: /mypath
4041
path: /api/greeting
4142
resp: json
4243
```

compile/apigw/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class OpenWhiskCompileHttpEvents {
6565
|| '_';
6666
}
6767

68+
calculateBasePath(httpEvent) {
69+
return httpEvent.basepath || `/${this.serverless.service.service}`;
70+
}
71+
6872
retrieveAuthKey(functionObject) {
6973
const annotations = functionObject.annotations || {}
7074
return annotations['require-whisk-auth']
@@ -82,7 +86,7 @@ class OpenWhiskCompileHttpEvents {
8286
compileHttpEvent(funcName, funcObj, http) {
8387
const options = this.parseHttpEvent(http);
8488
options.action = this.calculateFunctionName(funcName, funcObj);
85-
options.basepath = `/${this.serverless.service.service}`;
89+
options.basepath = this.calculateBasePath(http);
8690

8791
const secure_key = this.retrieveAuthKey(funcObj)
8892
if (secure_key) {

compile/apigw/tests/index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,13 @@ describe('OpenWhiskCompileHttpEvents', () => {
189189
return expect(result).to.deep.equal({basepath: '/my-service', relpath: '/api/foo/bar', operation: 'GET', action: '/sample_ns/my-service_action-name', responsetype: 'http'});
190190
});
191191

192-
/**
193-
it('should define http events with optional API GW parameters', () => {
192+
it('should define http events with explicit base path', () => {
194193
openwhiskCompileHttpEvents.serverless.service.service = 'my-service'
195194
openwhiskCompileHttpEvents.serverless.service.provider = {namespace: "sample_ns"};
196-
const http = {path: "/api/foo/bar", method: "GET", cors: true}
197-
let result = openwhiskCompileHttpEvents.compileHttpEvent('action-name', {}, http);
198-
expect(result.options).to.deep.equal({cors: true});
199-
http.cors = false
200-
result = openwhiskCompileHttpEvents.compileHttpEvent('action-name', {}, http);
201-
expect(result.options).to.deep.equal({cors: false});
195+
const http = {path: "/api/foo/bar", method: "GET", resp: 'http', basepath: '/custompath'}
196+
const result = openwhiskCompileHttpEvents.compileHttpEvent('action-name', {}, http);
197+
return expect(result).to.deep.equal({basepath: '/custompath', relpath: '/api/foo/bar', operation: 'GET', action: '/sample_ns/my-service_action-name', responsetype: 'http'});
202198
});
203-
*/
204199

205200
it('should throw if http event value invalid', () => {
206201
expect(() => openwhiskCompileHttpEvents.compileHttpEvent('', {}, 'OPERATION'))

0 commit comments

Comments
 (0)