dmc-local-app-router
v2.1.1
Published
SAP DMC Local App Router
Maintainers
Keywords
Readme
dmc-local-app-router
local app router used to run the DMC Custom View plugins locally without deploying to DMC.
What's New
- Added command line interface tools (cli) to zip the folder as per the 2502 DMC release. find more details about cli utils here
- Made mta.yaml as optional as per the 2502 DMC release update. You can set localDir property in local-configs.json file to use as webapp folder
Installation
run below commond to install latest version of module. here -g represents global installation. if you want to install locally, remove -g in below command.
npm i dmc-local-app-router@latest -gUse
- create
local-configs.jsonfile in the custom plugin root directory with below configs.
refer release 2.0.0 for using profile configs
{
"port": 8085, //port number
"localDir":"commonLib/lib", //(optional), it optional config. by default folder path maintained in mta.yaml file is used to serve the application. if specified, this property takes precedence
"manufacturing-execution-service": "https://<host>-#service#-ms.cfapps.eu20.hana.ondemand.com", //(depricated)integration URL to make internal API calls. it is depricated, so dont use this.
"routes":[
//public API router
{
"route":"/api/:servicePath*", //DMC Public API route
"uri":"https://api.test.<origin>.dmc.cloud.sap", // DMC Public API end point
"auth":"papiAuth" // Authorization, its user defined name. Maintain configs for this in auths section of this JSON file
},
//External API router
{
"route":"/capService/:servicePath*", // Any external router, its user define route
"uri":"https://<host>.cfapps.eu20.hana.ondemand.com", //Any external service end point like cap application
"auth":"capServiceAuth" //Authorization
},
//Static resource like common libraries, you can remove auth field
{
"route":"/commonLib/:servicePath*",
"uri":"https://<host>cfapps.eu20.hana.ondemand.com"
}
],
"auths":{
//Public API oAuth Config
"papiAuth":{
"authUrl": "https://<host>.authentication.eu20.hana.ondemand.com/oauth/token", //Authorixation URL
"clientId": "<clientID>",
"clientSecret": "<client Secret>"
},
//External Service oAuth Config
"capServiceAuth":{
"authUrl": "https://<host>.authentication.eu20.hana.ondemand.com/oauth/token", //Authorixation URL
"clientId": "<clientID>",
"clientSecret": "<client Secret>"
}
}
}
2.(deprecated) In package.json file add below start script to run the app;
No need to add configs in package.json after v 2.0.0
{
.....
"scripts": {
...
"start":"node node_modules/dmc-local-app-router/server.js", //from release 1.0.0, we can add profile config as well. using --profile parameter
"start-g":"node $(npm root -g)/dmc-local-app-router/server.js", //only works for mac users
....
},
...
}
3.(deprecated from v2.0.0)run npm run start to start the application
fron release 2.0.0, we can use --profile config to configure multiple profiles like dev,qa and prod etc.
run dmclar start command in root folder to start the application from release v2.0.0
for using the profile use dmclar start --profile dev or dmclar start -pr dev for using dev profile
Command line interface Tools
The dmclar CLI provides tools to start a local application and zip folders efficiently.
Usage
dmclar <command> [options]dmclar start|st [options]
Start the local application.
Options:
-pr, --profile→ Pass the profile info like'dev','qa','prod'.
example:
dmclar start --profile devdmclar zip [options]
Zip the content of the target folder. By default zip excluded node_modules, lib and .git folders. You can specify additional exclude folder/files with -e option.
if no options specified then takes source as current folder (./), target as name in the package.json file with .zip extention (./.zip)
Options:
--version→ Show version number. (boolean)-s, --source→ Source folder to zip. (string)-t, --target→ Target zip file path. (string)-e, --exclude→ Files or folders to exclude. (array)-h, --help→ Show help. (boolean)
example:
dmclar zip -s ./ -t ./output.zip -e dist/**,test/**Global Options
These options apply to all commands:
--version→ Show version number. (boolean)-h, --help→ Show help. (boolean)
Release Updates
2.1.1 Version
fixed the issue with localDir, taking preference to config localDir. if localDir not provided then if mta.yaml file exist then taking 'mtaConfigs.modules[0].path + "/webapp"' else considering current directory as local directory
let localDir;
if(configs.localDir){
localDir = configs.localDir;
}else if (fs.existsSync("mta.yaml")) {
mtaConfigs = yaml.parse(fs.readFileSync("mta.yaml", "utf-8"));
localDir = mtaConfigs.modules[0].path + "/webapp";
}else{
console.warn('mta.yaml file or localDir config not found in local-configs.json file. Using current root folder')
localDir = "./"
}2.1.0 Version
- added command line interface utility tool with command 'dmclar'. find different options using dmclar -h
2.0.3 Version
fixed the minor issue with query parameter parsing
2.0.2 Version
fixed the issue with response headers to support oData requests
2.0.1 Version
As per the 2411 SAP Digital manufacturing release, we can call few internal API's using publicAPi+'internal' suffix. So added 'x-dme-plant' header to all public api endpoints while running the application in the local
2.0.0 Version
Below changes made as part of this patch
- deprecated the use of
npm run startcommand to start the application. instead usedmclar startcommand directly.
you can safely remove the start scripts in your package.json file 2.added support to profile, which is useful to configure multiple environments in local-configs.json file. use
--profileor-prto pass profile as commandline argument
fallback machanisim implemented to take default configs if no profile passed
while starting the app use profile name to pick the respective configs
example:
dmclar stat --profile devdmclar start --profile qadmclar start --profile prodsample local-configs.json file
{
"[dev]": {
"port": 4005,
"manufacturing-execution-service": "<integration url for internal api calls>",
"routes": [
{
"route": "/api/:servicePath*",
"uri": "https://api.test.eu20.dmc.cloud.sap",
"auth": "papiAuth"
},
{
"route": "/capService/:servicePath*",
"uri": "<cap service url>",
"auth": "capServiceAuth"
},
{
"route": "/dmepapidest/:servicePath*",
"uri": "https://api.test.eu20.dmc.cloud.sap",
"auth": "papiAuth"
},
{
"route": "/commonLib/:servicePath*",
"uri": "<static lib url>"
}
],
"auths": {
"papiAuth": {
"authUrl": "<auth url>/oauth/token",
"clientId": "<client id>",
"clientSecret": "<client secret>"
},
"capServiceAuth": {
"authUrl": "<auth url>/oauth/token",
"clientId": "<client id>",
"clientSecret": "<client secret>"
}
}
},
"[qa]": {
"port": 4005,
"manufacturing-execution-service": "<integration url for internal api calls>",
"routes": [
{
"route": "/api/:servicePath*",
"uri": "https://api.test.eu20.dmc.cloud.sap",
"auth": "papiAuth"
},
{
"route": "/capService/:servicePath*",
"uri": "<cap service url>",
"auth": "capServiceAuth"
},
{
"route": "/dmepapidest/:servicePath*",
"uri": "https://api.test.eu20.dmc.cloud.sap",
"auth": "papiAuth"
},
{
"route": "/commonLib/:servicePath*",
"uri": "<static lib url>"
}
],
"auths": {
"papiAuth": {
"authUrl": "<auth url>/oauth/token",
"clientId": "<client id>",
"clientSecret": "<client secret>"
},
"capServiceAuth": {
"authUrl": "<auth url>/oauth/token",
"clientId": "<client id>",
"clientSecret": "<client secret>"
}
}
},
"[prod]": {
"port": 4005,
"manufacturing-execution-service": "<integration url for internal api calls>",
"routes": [
{
"route": "/api/:servicePath*",
"uri": "https://api.test.eu20.dmc.cloud.sap",
"auth": "papiAuth"
},
{
"route": "/capService/:servicePath*",
"uri": "<cap service url>",
"auth": "capServiceAuth"
},
{
"route": "/dmepapidest/:servicePath*",
"uri": "https://api.test.eu20.dmc.cloud.sap",
"auth": "papiAuth"
},
{
"route": "/commonLib/:servicePath*",
"uri": "<static lib url>"
}
],
"auths": {
"papiAuth": {
"authUrl": "<auth url>/oauth/token",
"clientId": "<client id>",
"clientSecret": "<client secret>"
},
"capServiceAuth": {
"authUrl": "<auth url>/oauth/token",
"clientId": "<client id>",
"clientSecret": "<client secret>"
}
}
}
}1.0.7 Version
Below changes made as part of this patch
1. Made 'auth' field in routes as optional field so you can add static resource routes without authorization
2. Added 'localDir' field to control while folder to be served
3. Added ReadME.md file with documentation