The logic services feature in Kony Fabric helps you import and integrate Node.js services (APIs) directly into Kony Fabric for developing server-side and networking applications. You can now enhance the capability of your Kony Fabric applications by adding custom services that are created within Node.js packages/projects. Node.js is an open-source and cross-platform runtime environment. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on Mac OS, Microsoft Windows, and Linux. Node.js also provides a rich library of JavaScript modules that simplify the development of web applications using Node.js. Currently, Kony Fabric supports Node.js V6.2.2 or above.
A Node.js package contains the following folders and files.
Swagger.json:
host
key should be present and hostname should be localhost and port value must be within 9000 - 10000.basePath
key should be present and value should with /services/
and followed by user app base path.mfidentitylevel
, which is optional, is used to enable auth protection for the resources. Possible values are: public
, protected
, and anonymous
.The following is a sample code for swagger.json.
{ "info": { "title": "Kony Fabric Logic (Node.js) sample application for managing Contacts", "version": "1.0.0", "description": "This sample application demonstrates use of Logic (Node.js) app in Kony Fabric" }, "host": "localhost:9000", "basePath": "/services/mailapp", "swagger": "2.0", "paths": { "/api/v1/contact": { "post": { "tags": [ "Contacts" ], "description": "Contact Details object", "produces": [ "application/json" ], "parameters": [ { "name": "Details", "description": "Contact Details", "in": "body", "required": true, "schema": { "$ref": "#/definitions/Contact Details" } } ], "responses": { "200": { "description": "Successfully created" } }, "mfidentitylevel": "public" } } }, "definitions": { "Contact Details": { "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "rollNumber": { "type": "string" }, "mobileNumber": { "type": "string" } } } }, "responses": {}, "parameters": {}, "securityDefinitions": {}, "tags": [] }
Package.json:
start
key must be present. Kony Fabric logic services uses the start key to start the user app. The following is a sample code for package.json. {
"name": "Sample_USERAPP",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"hjs": "~0.0.6",
"less-middleware": "1.0.x",
"mfgateway": "^1.0.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0",
"swagger-jsdoc": "^1.3.0"
}
}
User app: A user app is built on express JS. The following is a sample folder structure of a user app (Node.js package).
Sample_USERAPP ├───bin |_www
│ ├───public
├───routes |_ contact.js (Add your routes by adding new JS file here if you are using Kony Fabric sample app)
│
├───views
├───app.js ├───package.json ├───swagger.json
Node.js services published from the package are available in the Kony Fabric Console > Apps > Configure Services > Logic tab.
Important: Ensure that your package details (files and folders) are zipped in the root of the .zip file.
The logic services feature offers the following advantages for quickly mobilizing Node.js services in Kony Fabric for building apps:
For creating Web sites: Node.js technology helps you share code between the browser and the back end.
Read the following limitations for Node.js services before associating the services with Kony Fabric apps.
npm install save
option to install any modules.For example, to add the package in dependencies, follow the commands:
npm install --save my_dep
or
npm install -S my_dep
The above commands ensure that all the dependencies are updated to package.json
file.
npm_modules
folder in the final .zip file, which you want to upload to Kony Fabric. The npm_module
folder increases unnecessary package file size.Important: The user app should not depend on PORT environment variable. By default, if you are using express-generator to generate an express basic project, the bin/www
folder will have a PORT environment variable to refer to port value. In the bin/www
folder, use port number directly.
For example,
var port = normalizePort(process.env.PORT || '3000');
will become var port = normalizePort('9000');
The following sample code is to enable logging in the user apps. Using the mflogger, the user app logs can also be captured.
let mflogger; // Kony logger to capture application logs to display using logging service try {
// The following require statement imports the admin app's logging service into the user app through which user can capture logs.
mflogger = require(process.env.KONY_LOGIC_LOGGER);
} catch(e) {
// If the above statement fails, all the user app logs are captured in the default console output.
mflogger = console; }
Use the mflogger
instance for logging in the user app. Supported logging methods: debug
, info
, warn
, and error
.
mflogger.info('Message to log ...');
Unauthorized: If you see the following message indicates that your endpoint resource is protected by Kony Fabric identity services configured for your application. So you need to generate Kony Fabric login token and provide it as part of header with name as X-Kony-Authorization
{ "message": "Authentication failed" }
Error: If you see the following error, unpublish the user package from the API Management > Logic tab, and re-publish it.
{ "error": "Connection error." }
For technical questions, suggestions, and comments, or to report problems on Kony's product line, contact support@kony.com.
Node.js services integration in Kony Fabric apps involves the following two steps:
Rev | Author | Edits |
7.2 | SD | SD |
Copyright © 2020 Kony, Inc. All rights reserved. |