Skip to content

Commit c86a289

Browse files
authored
Add NodeJS sample service and enabler (#1140)
Add nodejs enabler and sample service Signed-off-by: at670475 <andrea.tabone@broadcom.com>
1 parent 77beaa7 commit c86a289

File tree

19 files changed

+550
-2
lines changed

19 files changed

+550
-2
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ Get in touch using [Zowe Communication Channels](https://github.com/zowe/communi
3535
| docker | Tool - Dev Docker Container |
3636
| docs | Documentation |
3737
| gateway-service | Core Service - Gateway Service |
38-
| onboarding-enabler-spring-v1-sample-app | Sample Service - Spring Enabler |
38+
| onboarding-enabler-spring-v1-sample-app | Sample Service - Spring Enabler |
39+
| onboarding-enabler-nodejs-sample-app | Sample Service - Node.js Enabler |
3940
| integration-tests | Test - Integration test |
4041
| keystore | Config - Local TLS config |
4142
| onboarding-enabler-java | APIML SDK - Java Enabler |
4243
| onboarding-enabler-java-sample-app | Sample Service - Java Enabler |
4344
| onboarding-enabler-spring | APIML SDK - Spring Enabler |
45+
| onboarding-enabler-nodejs | APIML SDK - Node.js Enabler |
4446
| passticket | Test - Passticket test tools |
4547
| scripts | Tool - Test and Build scripts |
4648
| security-service-client-spring | Library - Security Client |

Jenkinsfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pipeline {
8989
steps {
9090
sh 'npm install'
9191
sh 'cd api-catalog-ui/frontend && npm install'
92+
sh 'cd onboarding-enabler-nodejs-sample-app && npm install'
9293
}
9394
}
9495

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ For guidelines to onboard services, see [Zowe Docs#Onboarding Overview](https://
110110
| Core Service - Gateway Service | [Zowe Docs](https://docs.zowe.org/stable/getting-started/overview.html#api-mediation-layer) |
111111
| APIML SDK - Java Enabler | [Zowe Docs](https://docs.zowe.org/stable/extend/extend-apiml/onboard-plain-java-enabler.html) |
112112
| APIML SDK - Spring Enabler | [Zowe Docs](https://docs.zowe.org/stable/extend/extend-apiml/onboard-spring-boot-enabler.html) |
113+
| APIML SDK - Node.js Enabler | [Zowe Docs](https://docs.zowe.org/stable/extend/extend-apiml/onboard-nodejs-enabler.html) |
113114
| APIML SDK - ZAAS Client | [README](zaas-client/README.md) |
114115
| Sample Service - Java Enabler | [README](onboarding-enabler-java-sample-app/README.md) |
115116
| Sample Service - Spring Enabler | [README](onboarding-enabler-spring-v1-sample-app/README.md) |
116117
| Sample Service - Micronaut Enabler | [README](onboarding-enabler-micronaut-sample-app/README.md) |
118+
| Sample Service - NodeJS Enabler | [README](onboarding-enabler-nodejs-sample-app/README.md) |
117119

118120
## Contact Us
119121

docs/local-configuration.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ java -jar discoverable-client/build/libs/discoverable-client.jar --spring.config
5959
java -jar onboarding-enabler-spring-v1-sample-app/build/libs/enabler-springboot-1.5.9.RELEASE-sample.jar --spring.config.location=file:./config/local/onboarding-enabler-spring-v1-sample-app.yml
6060
```
6161

62+
### Sample Application - onboarding-enabler-nodejs-sample-app
63+
64+
To run onboarding-enabler-nodejs-sample-app, follow the steps below:
65+
66+
1. Run `npm run onboarding-enabler-spring-v1-sample-app` from the root project directory.
67+
68+
2. 2. Navigate to [https://localhost:10011]([https://localhost:10011]) and check if the service `HWEXPRESS` is registered to the discovery service. You should be able to reach the following endpoints using HTTPS:
69+
70+
* [https://localhost:10020/swagger.json](https://localhost:10020/swagger.json) which contains the API documentation
71+
* [https://localhost:10020/api/v1/status](https://localhost:10020/api/v1/status) for the health check endpoint containing the status of the application
72+
* [https://localhost:10020/api/v1/info](https://localhost:10020/api/v1/info) for the service information such as service ID and Node.js version.
73+
* [https://localhost:10020/api/v1/hello](https://localhost:10020/api/v1/hello) for the greeting endpoint
74+
* [https://localhost:10010/hwexpress/api/v1/hello](https://localhost:10010/hwexpress/api/v1/hello) for the greeting endpoint, routed through API Gateway
75+
76+
Go to the [API Catalog](https://localhost:10010/ui/v1/apicatalog) and check if the API documentation of the service is retrieved.
77+
78+
6279
### Sample Application - onboarding-enabler-java-sample-app
6380

6481
To run onboarding-enabler-java-sample-app, follow the steps below:

gradle/license.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ ext.projectsNeedLicense = [
1717
'security-module',
1818
'security-service-client-spring',
1919
'onboarding-enabler-java-sample-app',
20+
'onboarding-enabler-nodejs-sample-app',
2021
'onboarding-enabler-spring-v1-sample-app',
2122
'zowe-install',
2223
'onboarding-enabler-java',
2324
'onboarding-enabler-spring',
2425
'onboarding-enabler-micronaut',
2526
'onboarding-enabler-micronaut-sample-app',
27+
'onboarding-enabler-nodejs',
2628
'zaas-client',
2729
'mock-zosmf'
2830
]

gradle/sonar.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ project(":mock-zosmf") {
9999
}
100100
}
101101

102+
// Onboarding NodeJS enabler; sonar does not apply
103+
project(":onboarding-enabler-nodejs") {
104+
sonarqube {
105+
skipProject = true
106+
}
107+
}
108+
109+
// NodeJS sample service; sonar does not apply
110+
project(":onboarding-enabler-nodejs-sample-app") {
111+
sonarqube {
112+
skipProject = true
113+
}
114+
}
115+
102116
project(":integration-tests") {
103117
sonarqube {
104118
properties {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*/
10+
11+
package org.zowe.apiml.enablenodejssampleapp;
12+
13+
import io.restassured.RestAssured;
14+
import org.junit.jupiter.api.BeforeAll;
15+
import org.junit.jupiter.api.Test;
16+
import org.zowe.apiml.util.categories.TestsNotMeantForZowe;
17+
import org.zowe.apiml.util.http.HttpRequestUtils;
18+
19+
import java.net.URI;
20+
21+
import static io.restassured.RestAssured.given;
22+
import static org.apache.http.HttpStatus.SC_OK;
23+
import static org.hamcrest.Matchers.is;
24+
25+
@TestsNotMeantForZowe
26+
public class EnablerNodejsSampleAppEndpointTest {
27+
28+
private static final String APP_INFO_PATH = "/hwexpress/api/v1/info/";
29+
private static final String APP_INFO_HEALTH = "/hwexpress/api/v1/status/";
30+
private static final String JSON_CONTENT_TYPE = "application/json;charset=utf-8";
31+
private static final String GREETING_PATH = "/hwexpress/api/v1/hello";
32+
33+
@BeforeAll
34+
public static void beforeClass() {
35+
RestAssured.useRelaxedHTTPSValidation();
36+
}
37+
38+
@Test
39+
void shouldGetApplicationInfo() {
40+
URI uri = HttpRequestUtils.getUriFromGateway(APP_INFO_PATH);
41+
42+
given()
43+
.when()
44+
.get(uri)
45+
.then()
46+
.statusCode(is(SC_OK))
47+
.contentType(is(JSON_CONTENT_TYPE));
48+
}
49+
50+
@Test
51+
void shouldGetHealth() {
52+
URI uri = HttpRequestUtils.getUriFromGateway(APP_INFO_HEALTH);
53+
54+
given()
55+
.when()
56+
.get(uri)
57+
.then()
58+
.statusCode(is(SC_OK))
59+
.contentType(is(JSON_CONTENT_TYPE))
60+
.body("status", is("UP"));
61+
}
62+
63+
@Test
64+
void shouldGetGreeting() {
65+
URI uri = HttpRequestUtils.getUriFromGateway(GREETING_PATH);
66+
67+
given()
68+
.when()
69+
.get(uri)
70+
.then()
71+
.statusCode(is(SC_OK))
72+
.body("greeting", is("Hello World!"));
73+
}
74+
75+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Hello World API Service in Express
2+
3+
This is an example about how an API service implemented using [Node.js](https://nodejs.org/en/) and [Express](https://expressjs.com/) can be registered to the API Mediation Layer using the [apiml-onboarding-enabler-nodejs](https://www.npmjs.com/package/apiml-onboarding-enabler-nodejs) npm package.
4+
5+
6+
[index.js](src/index.js) starts the API service implemented in Express and registers it to the Discovery service using the Node.js onboarding enabler.
7+
8+
This example contains the full HTTPS validation of both Discovery Service and the Hello World service.
9+
10+
The certicate, private key for the service, and the local CA certificate are loaded from `keystore/localhost/localhost.keystore.p12`.
11+
12+
## How to run
13+
14+
You can start the service using:
15+
16+
cd helloworld-expressjs
17+
npm install
18+
node index.js
19+
20+
If the APIML is already running then you should see following messages:
21+
22+
hwexpress service listening on port 10020
23+
registered with eureka: hwexpress/localhost:hwexpress:10020
24+
25+
The you can access it via gateway it by:
26+
27+
http --verify=../keystore/local_ca/localca.cer GET https://localhost:10010/api/v1/hwexpress/hello
28+
29+
## Registration to the Discovery Service
30+
31+
The registration is performed by calling the NodeJS enabler library method `apiLayerService.connectToEureka()` in the `index.js` file.
32+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "helloworld-expressjs",
3+
"version": "0.3.0",
4+
"description": "Hello World Service in Express",
5+
"main": "src/index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/zowe/api-layer.git"
12+
},
13+
"author": "",
14+
"license": "EPL-2.0",
15+
"dependencies": {
16+
"apiml-onboarding-enabler-nodejs": "1.0.1",
17+
"express": "^4.16.4"
18+
}
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
../node_modules/
2+
../package-lock.json

0 commit comments

Comments
 (0)