A demo service to show how to develop a Platform 6 service with Node.js and TypeScript using Platform 6 Node.js connector.
- Launch a local instance of Platform 6.
- Read and fulfill the requirements of Platform 6 Node.js connector.
This project shows how to:
- create a simple Node.js application server,
- initialize a custom service on Platform 6,
- implement the endpoint that displays the service's user interface,
- send a request to a Platform 6 service,
- listen to any Platform 6 service requests
Every service should have a configuration interface. It is the main screen displayed when a user clicks on the associated entry menu in the Platform 6 Portal. Here's the configuration interface of our demo service:
This interface is defined in the file ServiceConfiguration.tsx
which has been developed using the framework React.
For now React is the only supported library on Platform 6.
The user interface must export a single main React component through a bundled JavaScript file (see Webpack for bundling and Babel for transpiling). This script will be injected and displayed on the Portal.
To help you build the user interface of your custom service, a set of components is ready for use on Platform 6.
They can be included as a JavaScript dependency from the library platform6-ui-components
.
The documentation of these components is available online.
Go in the root directory and install the global dependencies:
$ npm install
Go in the client's directory and install its dependencies:
$ cd client
$ npm install
Compile the TypeScript source files to generate the compiled bundle file client/build/ServiceConfiguration.bundle.js
:
$ npm run build
You can also use the watch mode to generate a new bundle file after every change made to the source files. The command is then:
npm run build:watch
.
The server in the demo is built using the framework Express. To launch it, from the root directory:
Install the dependencies:
$ npm install
Build and run the server:
$ npm run build
$ npm run start
You can also use the watch mode to generate a new bundle file after every change made to the server's code:
$ npm run build:watch
Simultaneously, in another shell, run the following command line to automatically restart the server after every build:
$ npm run server:watch
It should launch a server on the port 8000
then deploy the service demo.typescript on Platform 6.
An entry menu TypeScript should appear in the menu of the Portal.
When you click on it, it should make a request to the endpoint GET /api/${VERSION}/demo.typescript/portal
.
This endpoint returns the client's bundled JavaScript file ServiceConfiguration.bundle.js
that you built at the previous step.
Here is an example of the output:
/******/ (function(modules) { // webpackBootstrap↵/******/ // The module cache↵/******/ var installedModules = {};↵/******/↵/******/ // The require function↵/******/ function __webpack_require__(moduleId) [...]
The Portal will use this response to display the user interface of the service.
In this demo project, a listener to Platform 6 requests has been registred and the answer sent back by the TypeScript service has been implemented (server.ts).
Create a script in the Scripts service with the content below.
def commonMessage = [ headers: [ 'question': 'What time is it?' ] ]
print service.request('demo.typescript', commonMessage).headers['time']
Execute the script and you will see the custom service's response.
INFO [root] stdout: 16:31
MIT © Platform 6