Kony Fabric console User Guide: APIs in API Management > How Node.js works in MobileFabric

Logic - API Management

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.

Node.js Package Structure

A Node.js package contains the following folders and files.

Swagger.json:

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:

 {
  "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"
  }
}

Sample Node.js Package Structure

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

How Node.js Works in Kony Fabric

  1. Once you build a node.js package (in a .zip file), you need to import the package file into Kony Fabric Console.
  2. Publish the Node.js package into the Node.js runtime server through the console.

    Node.js services published from the package are available in the Kony Fabric Console > Apps > Configure Services > Logic tab.

  3. You can then integrate/associate services created in Node.js packages to Kony Fabric applications.
  4. Finally, the app needs to be published by selecting a Node.js environment.

Important: Ensure that your package details (files and folders) are zipped in the root of the .zip file.

Benefits of Node.js App Development

The logic services feature offers the following advantages for quickly mobilizing Node.js services in Kony Fabric for building apps:

Use Cases

Limitations

Read the following limitations for Node.js services before associating the services with Kony Fabric apps.

Prerequisites

Logging Service Support for User App

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 ...');

Troubleshooting

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

Node.js services integration in Kony Fabric apps involves the following two steps:

  1. How to Publish Node.js Package into Node.js Runtime Server in API Management. This section details how to import a Node.js package into Kony Fabric Console and publish the package to the Node.js Runtime Server.
  2. How to Integrate Node.js Services into Kony Fabric Apps. This section details how to integrate Node.js services to Kony Fabric apps.

 

 

 

 

 

 

 

Rev Author Edits
7.2 SD SD
Copyright © 2020 Kony, Inc. All rights reserved.