changed readme, startup script, yml file, IBM-850

Signed-off-by: Nakul Manchanda <nakul.manchanda@ibm.com>
This commit is contained in:
Nakul Manchanda
2019-03-25 15:52:39 -04:00
parent 1f23e15fd1
commit cac246acf5
6 changed files with 92 additions and 87 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
coverage/
node_modules/
.vscode/
.vscode/
output

View File

@@ -6,7 +6,7 @@ A sample node js api for finding cars and accounts for a dealership,its used her
## Steps
**Note**
`Only rest api with https support can be deployed behind API/ML, make sure to enable https support in your respective api.
`Only rest api with https support can be deployed behind API/ML, make sure to enable https support in your rest api.
`
@@ -17,9 +17,10 @@ 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
### 1) Clone the repository, install node packages and verify routes locally
```
//on local
git clone https://github.com/zowe/sample-node-api
cd sample-node-api
npm install
@@ -31,49 +32,70 @@ Open your local browser and try accessing
`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
### 2) Transfer project files from local to remote host
**Note**
Don't transfer `node_moules` folder, we can do install npm install later on remote server itself to pull down required node packages
```
// on remote - Create placeholder directory for your node app
ssh ibmuser@my.mainframe.com
cd /u/zowe/ibmuser/1.0.0/
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
//on local - use scp to transfer project files
scp data.js ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.0/sample-node-api
scp package.json ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.0/sample-node-api
scp package-lock.json ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.0/sample-node-api
scp sample-node-api.yml ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.0/sample-node-api/sample-node-api.yml.1047
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
scp -r scripts ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.0/sample-node-api/scripts
scp -r server ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.0/sample-node-api/server
scp -r sslcert ibmuser@my.mainframe.com:/u/zowe/ibmuser/1.0.0/sample-node-api/sslcert
```
4) ssh again, to edit `run-zowe.sh`
### 3) Install node packages required by API
```
ssh ibmuser@my.mainframe.com
// on remote
cd /u/zowe/ibmuser/1.0.0/sample-node-api
npm install
```
### 4) Register a plugin API/ML layer using yml file
**Note**
Require encoding for `sample-node-api.yml` is `IBM-850`, use `iconv` utility to convert it to correct format
Yaml config file needs to be present in api-defs folder along-with other statically discovered API example jobs.yml, uss.yml etc
```
// on remote
cd /u/zowe/ibmuser/1.0.0/sample-node-api
iconv -t IBM-850 -f IBM-1047 sample-node-api.yml.1047 > sample-node-api.yml
mv sample-node-api.yml ../api-mediation/api-defs/
```
### 5) Edit `run-zowe.sh` on remote append node app startup script
```
// on remote
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
Append following start command for sample-node-api, among similar command from another services
```
`dirname $0`/../../sample-node-api/scripts/start-sample-node-api.sh
```
6) Restart Zowe
### 6) Restart Zowe
7) Access newly deployed webservice behind api/v1
### 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/`

View File

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

View File

@@ -1,31 +1,18 @@
#!/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 &
#!/bin/sh
# find node bin
if [ ! -z "$NODE_HOME" ]; then
NODE_BIN=${NODE_HOME}/bin/node
else
echo "Error: cannot find node bin, node app did not start"
exit 1
fi
# get current script directory
SCRIPT_DIR=$(dirname "$0")
# get to new node app source directory
cd "$SCRIPT_DIR/.."
# start service
$NODE_BIN server/app.js &

View File

@@ -3,11 +3,9 @@ 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);
const cors = require('cors')
const { HTTPS_PORT } = require('./config.json');
const privateKey = fs.readFileSync(path.resolve(__dirname, "../sslcert/server.key"), 'utf8');
const certificate = fs.readFileSync(path.resolve(__dirname, "../sslcert/server.cert"), 'utf8');
@@ -17,18 +15,15 @@ const app = express();
//TODO: use for whitelist only
app.use(cors());
const routes = require('./routes/index.route');
app.get('/', (req, res) => res.send('Hello World!'));
app.use(routes);
const httpServer = http.createServer(app);
// const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);
httpServer.listen(HTTP_PORT);
// httpServer.listen(HTTP_PORT);
httpsServer.listen(HTTPS_PORT);
console.log(`server listening at port ${HTTPS_PORT}`);
module.exports = { app };

View File

@@ -1,4 +1,3 @@
{
"HTTP_PORT": 3000,
"HTTPS_PORT": 4000
{
"HTTPS_PORT": 18000
}