update sample-node-api

Signed-off-by: Nakul Manchanda <nakul.manchanda@ibm.com>
This commit is contained in:
Nakul Manchanda
2020-02-13 13:47:42 -05:00
parent 6aa526a638
commit 26f8db6f9b
8 changed files with 482 additions and 1013 deletions

2
.gitignore vendored
View File

@@ -2,4 +2,4 @@ coverage/
node_modules/
.vscode/
output
steps.md
dist/**

View File

@@ -8,6 +8,8 @@ A sample node js api for finding cars and accounts for a dealership,its used her
`
This sample express app, has https enabled already.
## On Local:
### 1) Clone the repository, install node packages and verify routes locally
```
@@ -30,20 +32,56 @@ Open your local browser and try accessing
Don't transfer `node_modules` folder, we can do install npm install later on remote server itself to pull down required node packages
```
scp -r sample-node-api ibmuser@my.mainframe.com:</usr/lpp/extender>/sample-node-api
cd sample-node-api
npm run build
scp -r dist ibmuser@my.mainframe.com:</usr/lpp/extender>/sample-node-api
```
### 3) Register as External Component
Append to EXTERNAL_COMPONENT </usr/lpp/extender>/sample-node-api/bin in INSTANCE_DIR/instance.env
## On Server
### 1) login
```
ssh ibmuser@my.mainframe.com
```
### 2) install dependencies
```
cd </usr/lpp/extender>/sample-node-api
npm install --only=prod
```
### 3) Manage lifecycle of service with core zowe components
Use property `EXTERNAL_COMPONENT` located in file `$INSTANCE_DIR/instance.env`
Append it with your service lifecycle scripts.
In our sample it is:
```
vi INSTANCE_DIR/instance.env
EXTERNAL_COMPONENTS=</usr/lpp/extender>/sample-node-api/bin
```
It expects folder with `start.sh`, `configure.sh` and `validate.sh`, provides lifecycle hooks to configure and start your api component with rest of zowe.
We expect following in service folder `start.sh`, `configure.sh` and `validate.sh`.
In our case its bin folder with relevant scripts.
### 4) Access newly deployed webservice behind api/v1
`configure.sh` it adds static definition for sample-node-api to folder ${INSTANCE_DIR}/workspace/api-mediation/api-defs in IBM-850 encoding
`start.sh` starts node app on configured port
`env.sh` its custom script use to configure port for our node app, feel free to use your desired way
### 4) Access newly deployed webservice
Please see static definition file `sample-node-api.yml`
It configures service endpoint as `sample-node-api` with property `serviceId`
We also provide api gateway base path `api\v1` with property `gatewayUrl` in same file.
In effect, service can be accessed with following url:
`https://{host}:{GATEWAY_PORT}/{gatewayUrl}/{serviceId}/*`
where `GATEWAY_PORT` is configured in $INSTANCE_DIR/instance.env
Verify by accessing following:
`https://my.mainframe.com:7554/api/v1/sample-node-api/accounts/`
`https://my.mainframe.com:7554/api/v1/sample-node-api/accounts/1/`
`https://my.mainframe.com:7554/api/v1/sample-node-api/accounts/1/cars/`

View File

@@ -10,15 +10,55 @@
# Copyright IBM Corporation 2020
################################################################################
. env.sh
COMPONENT_DIR="${ROOT_DIR}/components/${MY_API_NAME}"
# Variables required on shell:
# STATIC_DEF_CONFIG_DIR=${INSTANCE_DIR}/workspace/api-mediation/api-defs
# ZOWE_EXPLORER_HOST
# MY_API_NAME
# MY_API_PORT
# copy static definition for sample-node-api to make fresh copy on every start
cp ${COMPONENT_DIR}/${MY_API_NAME}.yml ${COMPONENT_DIR}/${MY_API_NAME}.ebcidic.yml
echo 'sample-node-api configure begin'
#configure based on env.sh
sed -i 's/mymainframe.ibm.com/${ZOWE_EXPLORER_HOST}/g' ${COMPONENT_DIR}/${MY_API_NAME}.ebcidic.yml
sed -i 's/18000/${MY_API_PORT}/g' ${COMPONENT_DIR}/${MY_API_NAME}.ebcidic.yml
BASE_DIR=$(dirname "$0")
COMPONENT_DIR="$( cd "${BASE_DIR}/.." >/dev/null 2>&1 && pwd )"
cd $OLDPWD
echo "COMPONENT_DIR: ${COMPONENT_DIR}"
iconv -f IBM-1047 -t IBM-850 ${COMPONENT_DIR}/${MY_API_NAME}.ebcidic.yml > $STATIC_DEF_CONFIG_DIR/${MY_API_NAME}.yml
chmod 770 $STATIC_DEF_CONFIG_DIR/${MY_API_NAME}.yml
echo 'load sample-node-api config'
# load config from env
. ${COMPONENT_DIR}/bin/env.sh
echo 'make sample-node-api.ebcidic.yml with replaced env variable'
# Add static definition for sample-node-api
cat <<EOF >${STATIC_DEF_CONFIG_DIR}/${MY_API_NAME}.ebcidic.yml
#
services:
- serviceId: ${MY_API_NAME}
title: ${MY_API_NAME}
description: Example ${MY_API_NAME} Application
catalogUiTileId: ${MY_API_NAME}
instanceBaseUrls:
- https://${ZOWE_EXPLORER_HOST}:${MY_API_PORT}/
homePageRelativeUrl: # Home page is at the same URL
routedServices:
- gatewayUrl: api/v1 # [api/ui/ws]/v{majorVersion}
serviceRelativeUrl:
apiInfo:
- apiId: com.ibm.${MY_API_NAME}
gatewayUrl: api/v1
version: 0.0.1
catalogUiTiles:
${MY_API_NAME}:
title: ${MY_API_NAME}
description: Example ${MY_API_NAME} Application
EOF
echo 'change sample-node-api.ebcidic.yml encoding from ibm-1047 to ibm-850'
# basically this yml file is only thing we need to do register our service with apiml
iconv -f IBM-1047 -t IBM-850 ${STATIC_DEF_CONFIG_DIR}/${MY_API_NAME}.ebcidic.yml > $STATIC_DEF_CONFIG_DIR/${MY_API_NAME}.yml
rm ${STATIC_DEF_CONFIG_DIR}/${MY_API_NAME}.ebcidic.yml
chmod 770 $STATIC_DEF_CONFIG_DIR/${MY_API_NAME}.yml
echo 'sample-node-api configure done'

View File

@@ -10,34 +10,34 @@
# Copyright IBM Corporation 2020
################################################################################
. env.sh
COMPONENT_DIR="${ROOT_DIR}/components/${MY_API_NAME}"
# Variables required on shell:
# STATIC_DEF_CONFIG_DIR=${INSTANCE_DIR}/workspace/api-mediation/api-defs
# ZOWE_EXPLORER_HOST
# MY_API_NAME
# MY_API_PORT
echo 'sample-node-api configure begin'
# Add static definition for sample-node-api
cat <<EOF >${STATIC_DEF_CONFIG_DIR}/${MY_API_NAME}.ebcidic.yml
#
services:
- serviceId: ${MY_API_NAME}
title: ${MY_API_NAME}
description: Example ${MY_API_NAME} Application
catalogUiTileId: ${MY_API_NAME}
instanceBaseUrls:
- https://${ZOWE_EXPLORER_HOST}:${MY_API_PORT}/
homePageRelativeUrl: # Home page is at the same URL
routedServices:
- gatewayUrl: api/v1 # [api/ui/ws]/v{majorVersion}
serviceRelativeUrl:
apiInfo:
- apiId: com.ibm.${MY_API_NAME}
gatewayUrl: api/v1
version: 0.0.1
BASE_DIR=$(dirname "$0")
COMPONENT_DIR="$( cd "${BASE_DIR}/.." >/dev/null 2>&1 && pwd )"
cd $OLDPWD
echo "COMPONENT_DIR: ${COMPONENT_DIR}"
catalogUiTiles:
${MY_API_NAME}:
title: ${MY_API_NAME}
description: Example ${MY_API_NAME} Application
EOF
# load config from env
echo 'load sample-node-api config'
. ${COMPONENT_DIR}/bin/env.sh
echo 'Add static definition for sample-node-api'
#configure based on env.sh
sed -e "s/mymainframe.ibm.com/${ZOWE_EXPLORER_HOST}/g" \
-e "s/18000/${MY_API_PORT}/g" \
${COMPONENT_DIR}/${MY_API_NAME}.yml \
> ${STATIC_DEF_CONFIG_DIR}/${MY_API_NAME}.ebcidic.yml
echo 'change sample-node-api.ebcidic.yml encoding from ibm-1047 to ibm-850'
# basically this yml file is only thing we need to do register our service with apiml
iconv -f IBM-1047 -t IBM-850 ${STATIC_DEF_CONFIG_DIR}/${MY_API_NAME}.ebcidic.yml > $STATIC_DEF_CONFIG_DIR/${MY_API_NAME}.yml
rm ${STATIC_DEF_CONFIG_DIR}/${MY_API_NAME}.ebcidic.yml
chmod 770 $STATIC_DEF_CONFIG_DIR/${MY_API_NAME}.yml
chmod 770 $STATIC_DEF_CONFIG_DIR/${MY_API_NAME}.yml
echo 'sample-node-api configure done'

View File

@@ -1,3 +1,2 @@
MY_API_NAME='sample-node-api'
MY_API_PORT='18000'
MY_API_PORT='18000'

View File

@@ -10,19 +10,35 @@
# Copyright IBM Corporation 2020
################################################################################
# Variables required on shell:
# NODE_HOME
# MY_API_NAME
# MY_API_PORT
# KEYSTORE_KEY
# KEYSTORE_CERTIFICATE
echo 'sample-node-api start begin'
# find node bin
NODE_BIN=${NODE_HOME}/bin/node
#load component config
. env.sh
BASE_DIR=$(dirname "$0")
COMPONENT_DIR="$( cd "${BASE_DIR}/.." >/dev/null 2>&1 && pwd )"
cd $OLDPWD
echo "COMPONENT_DIR: ${COMPONENT_DIR}"
COMPONENT_DIR="${ROOT_DIR}/components/${MY_API_NAME}"
# load config from env
echo 'load sample-node-api config'
. ${COMPONENT_DIR}/bin/env.sh
echo "start sample-node-api app on port ${MY_API_PORT}"
#start component
$NODE_BIN $COMPONENT_DIR/server/app.js \
--service ${MY_API_NAME} \
--port ${MY_API_PORT} \
--key ${KEYSTORE_KEY} \
--cert ${KEYSTORE_CERTIFICATE} \
-v &
-v &
echo 'sample-node-api start done'

1296
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,20 +4,20 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node server/app.js"
"start": "node server/app.js",
"build": "npm run clean && cp -r server dist/server && cp -r bin dist/bin && cp *.yml dist && cp *.json dist && cp *.js dist && rimraf dist/package-lock.json",
"clean": "rimraf dist && mkdirp dist"
},
"author": "",
"license": "ISC",
"dependencies": {
"assert": "^1.4.1",
"cors": "^2.8.5",
"cucumber": "^5.1.0",
"express": "^4.16.4",
"istanbul": "^0.4.5",
"supertest": "^3.4.2",
"yargs": "^15.1.0"
"yargs": "^8.0.2"
},
"devDependencies": {
"node-fetch": "^2.3.0"
"mkdirp": "^1.0.3",
"node-fetch": "^2.3.0",
"rimraf": "^3.0.2"
}
}