This is an automated email from the ASF dual-hosted git repository.
mrutkowski pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-devtools.git
The following commit(s) were added to refs/heads/master by this push:
new b574a1a adding http methods (#208)
b574a1a is described below
commit b574a1a44f86df6f615a82e2df36e0b013069165
Author: Priti Desai <[email protected]>
AuthorDate: Fri Mar 15 12:32:49 2019 -0700
adding http methods (#208)
---
knative-build/runtimes/javascript/app.js | 2 +-
.../runtimes/javascript/buildtemplate.yaml | 3 ++
.../runtimes/javascript/platform/platform.js | 37 ++++++++++++++++++++++
3 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/knative-build/runtimes/javascript/app.js
b/knative-build/runtimes/javascript/app.js
index 61f7193..3f0eb26 100644
--- a/knative-build/runtimes/javascript/app.js
+++ b/knative-build/runtimes/javascript/app.js
@@ -71,7 +71,7 @@ if (targetPlatform === runtime_platform.openwhisk ) {
} else if (targetPlatform === runtime_platform.knative) {
var platformFactory = require('./platform/platform.js');
var platform = new platformFactory("knative", service, config);
- app.post('/', platform.run);
+ platform.registerHandlers(app, platform)
} else {
console.error("Environment variable '__OW_RUNTIME_PLATFORM' has an
unrecognized value ("+targetPlatform+").");
}
diff --git a/knative-build/runtimes/javascript/buildtemplate.yaml
b/knative-build/runtimes/javascript/buildtemplate.yaml
index e63e36f..dc7f70a 100644
--- a/knative-build/runtimes/javascript/buildtemplate.yaml
+++ b/knative-build/runtimes/javascript/buildtemplate.yaml
@@ -29,6 +29,9 @@ spec:
- name: OW_ACTION_BINARY
description: flag to indicate zip function, for zip actions,
"__OW_ACTION_CODE" must be base64 encoded string
default: "false"
+ - name: OW_HTTP_METHODS
+ description: list of HTTP methods, any combination of [GET, POST, PUT, and
DELETE], default is [POST]
+ default: "[POST]"
steps:
- name: add-ow-env-to-dockerfile
image: "gcr.io/kaniko-project/executor:debug"
diff --git a/knative-build/runtimes/javascript/platform/platform.js
b/knative-build/runtimes/javascript/platform/platform.js
index d448b39..c6a5389 100644
--- a/knative-build/runtimes/javascript/platform/platform.js
+++ b/knative-build/runtimes/javascript/platform/platform.js
@@ -182,6 +182,8 @@ function preProcessRequest(req){
// process per-activation (i.e, "run") data
preProcessActivationData(env, activationData);
+ preProcessHTTPContext(req);
+
} catch(e){
console.error(e);
DEBUG.functionEndError(e.message);
@@ -234,6 +236,7 @@ function postProcessResponse(result, res) {
DEBUG.functionEnd();
}
+
function PlatformFactory(id, svc, cfg) {
DEBUG.dumpObject(id, "Platform" );
@@ -268,6 +271,40 @@ function PlatformFactory(id, svc, cfg) {
res.status(500).json({error: "internal error"})
}
}
+
+ var http_method = {
+ get: 'GET',
+ post: 'POST',
+ put: 'PUT',
+ delete: 'DELETE',
+ };
+
+ this.registerHandlers = function(app, platform) {
+ var httpMethods = process.env.__OW_HTTP_METHODS;
+ // default to "[post]" HTTP method if not defined
+ if (typeof httpMethods === "undefined" ||
!Array.isArray(httpMethods)) {
+ console.error("__OW_HTTP_METHODS is undefined; defaulting to
'[post]' ...");
+ httpMethods = [http_method.post];
+ }
+ httpMethods.forEach(function (method) {
+ switch (method.toUpperCase()) {
+ case http_method.get:
+ app.get('/', platform.run);
+ break;
+ case http_method.post:
+ app.post('/', platform.run);
+ break;
+ case http_method.put:
+ app.put('/', platform.run);
+ break;
+ case http_method.delete:
+ app.delete('/', platform.run);
+ break;
+ default:
+ console.error("Environment variable
'__OW_HTTP_METHODS' has an unrecognized value (" + method + ").");
+ }
+ });
+ }
};
module.exports = PlatformFactory;