added readme, yaml file and startup script

Signed-off-by: Nakul Manchanda <nakul.manchanda@ibm.com>
This commit is contained in:
Nakul Manchanda
2019-03-21 20:45:48 -04:00
parent af62b9c014
commit 9573cbcb20
6 changed files with 149 additions and 9 deletions

View File

@@ -1,2 +1,82 @@
# sample-node-api
A sample node js api for finding cars and accounts for a dealership
# sample-node-api
A sample node js api for finding cars and accounts for a dealership,its used here to demonstrate the steps to extend API/ML with your own rest api.
## Manual Installation
### Steps
Note:
`Only rest api with https support can be deployed behind API/ML, make sure to enable https support in your respective api.
`
Note:
Replace `/u/zowe/ibmuser/1.0.0/` with your zowe installation folder
Replace `ibmuser@my.mainframe.com` with your username and mainframe-ip
This sample express app, has https enabled already.
1) Clone the repository, install node packages and verify routes locally
```
git clone https://github.com/zowe/sample-node-api
cd sample-node-api
npm install
npm start
```
Open your local browser and try accessing
`https://localhost:4000/accounts/`
`https://localhost:4000/accounts/1`
`https://localhost:4000/accounts/1/cars/`
2) Transfer yaml from local to host, to register a plugin API/ML layer
```
scp sample-node-api.yaml ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.0/api-mediation/api-defs
```
3) create placeholder directory for your node app
```
ssh ibmuser@my.mainframe.com
mkdir sample-node-api
```
4) Transfer of file from local to remote host
```
scp data.js ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.1/sample-node-api
scp package.json ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.1/sample-node-api
scp package-lock.json ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.1/sample-node-api
scp -r scripts ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.1/sample-node-api/scripts
scp -r server ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.1/sample-node-api/server
scp -r sslcert ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.1/sample-node-api/sslcert
```
4) ssh again, to edit `run-zowe.sh`
```
ssh ibmuser@my.mainframe.com
cd /u/zowe/ibmuser/1.0.0/scripts/internal/
vi run-zowe.sh
```
5) Append following start command for sample-node-api, among simillar command from another services
```
`dirname $0`/../../sample-node-api/scripts/start-sample-node-api.sh
```
6) Restart Zowe
7) Access newly deployed webservice behind api/v1
`https://my.mainframe.com:7554/api/v1/node-sample-api/accounts/`
`https://my.mainframe.com:7554/api/v1/node-sample-api/accounts/1/`
`https://my.mainframe.com:7554/api/v1/node-sample-api/accounts/1/cars/`

9
package-lock.json generated
View File

@@ -208,6 +208,15 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"cors": {
"version": "2.8.5",
"resolved": "https://gizaartifactory.jfrog.io/gizaartifactory/api/npm/npm-release/cors/-/cors-2.8.5.tgz",
"integrity": "sha1-6sEdpRWS3Ya58G9uesKTs9+HXSk=",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"cross-spawn": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",

View File

@@ -10,10 +10,11 @@
"author": "",
"license": "ISC",
"dependencies": {
"assert": "^1.4.1",
"cors": "^2.8.5",
"cucumber": "^5.1.0",
"express": "^4.16.4",
"supertest": "^3.4.2",
"assert": "^1.4.1",
"istanbul": "^0.4.5"
"istanbul": "^0.4.5",
"supertest": "^3.4.2"
}
}

20
sample-node-api.yaml Normal file
View File

@@ -0,0 +1,20 @@
services:
- serviceId: node-sample-api
title: Node Sample API
description: Example Node.js Application
catalogUiTileId: node-sample-api
instanceBaseUrls:
- https://my.mainframe.com:18000/
homePageRelativeUrl: # Home page is at the same URL
routedServices:
- gatewayUrl: api/v1 # [api/ui/ws]/v{majorVersion}
serviceRelativeUrl:
apiInfo:
- apiId: com.ibm.node-sample-api
gatewayUrl: api/v1
version: 0.0.1
catalogUiTiles:
node-sample-api:
title: Node Sample API
description: Example Node.js Application

View File

@@ -0,0 +1,31 @@
#!/bin/sh
################################################################################
# This program and the accompanying materials are made available under the terms of the
# Eclipse Public License v2.0 which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-v20.html
#
# SPDX-License-Identifier: EPL-2.0
#
# Copyright IBM Corporation 2018, 2019
################################################################################
################################################################################
# start sample node api
#
# NOTE: this script is intended to be called by ZOWE service, not manually by .
# find node bin
if [ ! -z "$NODE_HOME" ]; then
NODE_BIN=${NODE_HOME}/bin/node
else
echo "Error: cannot find node bin, JES Explorer UI is not started."
exit 1
fi
# get current script directory
SCRIPT_DIR=$(dirname "$0")
# get current ui server directory
SERVER_DIR=$(cd "$SCRIPT_DIR/.."; pwd)
# start service
$NODE_BIN npm run start &

View File

@@ -3,6 +3,7 @@ const http = require('http');
const https = require('https');
const fs = require('fs');
const path = require("path");
var cors = require('cors')
const { HTTP_PORT, HTTPS_PORT } = require('./config.json');
console.log(HTTPS_PORT);
@@ -12,12 +13,10 @@ const privateKey = fs.readFileSync(path.resolve(__dirname, "../sslcert/server.ke
const certificate = fs.readFileSync(path.resolve(__dirname, "../sslcert/server.cert"), 'utf8');
const credentials = { key: privateKey, cert: certificate };
const app = express();
const port = 3000;
//TODO: use for whitelist only
app.use(cors());
const routes = require('./routes/index.route');