Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
feat(openwhisk): add request.pathInfo (#257)
Browse files Browse the repository at this point in the history
fixes #255
  • Loading branch information
tripodsan authored Apr 16, 2019
1 parent 25af1c3 commit 8485626
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/request.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions docs/request.schema.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/context.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export interface Request {
* The path of the client request URL
*/
path?: string;
/**
* The part of the client path that is relative to the rootPath
*/
pathInfo?: string;
/**
* The request root path of the current strain.
*/
rootPath?: string;
/**
* The selector (sub-type indicator)
*/
Expand Down
14 changes: 14 additions & 0 deletions src/schemas/request.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
"/docs/api/general/index.nav.html"
]
},
"pathInfo": {
"type": "string",
"description": "The part of the client path that is relative to the rootPath",
"examples": [
"/general/index.nav.html"
]
},
"rootPath": {
"type": "string",
"description": "The request root path of the current strain.",
"examples": [
"/docs/api"
]
},
"selector": {
"type": "string",
"description": "The selector (sub-type indicator)",
Expand Down
6 changes: 6 additions & 0 deletions src/utils/openwhisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ function extractClientRequest(action) {
return {};
}
const reqPath = buildPath(request);
let pathInfo = reqPath.replace(/\/*$/, '');
if (`${pathInfo}/`.startsWith(`${request.params.rootPath}/`)) {
pathInfo = pathInfo.substring(request.params.rootPath.length);
}
const query = request.params.params ? `?${request.params.params}` : '';
return {
// the edge encodes the client request parameters into the `params` param ;-)
Expand All @@ -61,6 +65,8 @@ function extractClientRequest(action) {
extension: request.params.extension || '',
selector: request.params.selector || '',
url: `${reqPath}${query}`,
rootPath: request.params.rootPath,
pathInfo,
};
}

Expand Down
6 changes: 6 additions & 0 deletions test/testOpenwhisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ describe('Testing OpenWhisk adapter', () => {
},
url: '/api/general/index.html?a=42&b=green',
path: '/api/general/index.html',
rootPath: '/api/general',
pathInfo: '/index.html',
selector: '',
});
});
Expand Down Expand Up @@ -202,6 +204,8 @@ describe('Testing OpenWhisk adapter', () => {
params: {},
url: '/api/general/index.html',
path: '/api/general/index.html',
rootPath: '/api/general',
pathInfo: '/index.html',
selector: '',
});
});
Expand Down Expand Up @@ -259,6 +263,8 @@ describe('Testing OpenWhisk adapter', () => {
extension: 'html',
selector: 'print.preview',
url: '/docs/test.print.preview.html?a=42&b=green',
rootPath: '/docs',
pathInfo: '/test.print.preview.html',
},
});
});
Expand Down

0 comments on commit 8485626

Please sign in to comment.