pritidesai commented on a change in pull request #119: An ability to run on 
Knative along with OpenWhisk
URL: 
https://github.com/apache/incubator-openwhisk-runtime-nodejs/pull/119#discussion_r276476794
 
 

 ##########
 File path: core/nodejsActionBase/app.js
 ##########
 @@ -15,74 +15,80 @@
  * limitations under the License.
  */
 
+// __OW_ALLOW_CONCURRENT: see docs/concurrency.md
 var config = {
-        'port': 8080,
-        'apiHost': process.env.__OW_API_HOST,
-        'allowConcurrent': process.env.__OW_ALLOW_CONCURRENT
+    'port': 8080,
+    'apiHost': process.env.__OW_API_HOST,
+    'allowConcurrent': process.env.__OW_ALLOW_CONCURRENT,
+    'requestBodyLimit': "48mb"
 };
 
 var bodyParser = require('body-parser');
 var express    = require('express');
 
+/**
+ * instantiate app as an instance of Express
+ * i.e. app starts the server
+ */
 var app = express();
 
-
 /**
  * instantiate an object which handles REST calls from the Invoker
  */
 var service = require('./src/service').getService(config);
 
-app.set('port', config.port);
-app.use(bodyParser.json({ limit: "48mb" }));
+/**
+ * setup a middleware layer to restrict the request body size
+ * this middleware is called every time a request is sent to the server
+ */
+app.use(bodyParser.json({ limit: config.requestBodyLimit }));
+
+// identify the target Serverless platform
+const platformFactory = require('./platform/platform.js');
+const factory = new platformFactory(app, config, service);
+var targetPlatform = process.env.__OW_RUNTIME_PLATFORM;
+
+// default to "openwhisk" platform initialization if not defined
+// TODO export isvalid() from platform, if undefined this is OK to default, 
but if not valid value then error out
+if(typeof targetPlatform === "undefined") {
+    targetPlatform = platformFactory.PLATFORM_OPENWHISK;
+    // console.log("__OW_RUNTIME_PLATFORM is undefined; defaulting to 
'openwhisk' ...");
+}
+
+if(!platformFactory.isSupportedPlatform(targetPlatform)){
+    console.error("__OW_RUNTIME_PLATFORM ("+targetPlatform+") is not supported 
by the runtime.");
+    process.exit(9);
+}
+
+/**
+ * Register different endpoint handlers depending on target PLATFORM and its 
expected behavior.
+ * In addition, register request pre-processors and/or response 
post-processors as needed
+ * to move data where the platform and function author expects it to be.
+ */
 
-app.post('/init', wrapEndpoint(service.initCode));
-app.post('/run',  wrapEndpoint(service.runCode));
+var platformImpl = factory.createPlatformImpl(targetPlatform);
+
+if(typeof platformImpl == "undefined") {
 
 Review comment:
   Addressed in PR # 122

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to