You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2019/07/26 11:46:31 UTC
[sling-whiteboard] branch master updated (9f00339 -> 3879491)
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git.
from 9f00339 Fix 'action not found' case
new 1684a6c Content-type fix, star resource type, 500 status code
new 3879491 Markdown renderer action
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
serverless-microsling/install | 14 +++++++--
serverless-microsling/lib/openwhisk-renderer.js | 4 ++-
serverless-microsling/lib/render.js | 4 +--
serverless-microsling/microsling.js | 6 ++--
.../{somedoc-html.js => markdown-default.js} | 35 +++++++---------------
5 files changed, 30 insertions(+), 33 deletions(-)
copy serverless-microsling/rendering-actions/{somedoc-html.js => markdown-default.js} (63%)
[sling-whiteboard] 01/02: Content-type fix, star resource type,
500 status code
Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit 1684a6c9bc6941702a555286dbd8b91bedd85ff5
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jul 26 13:46:02 2019 +0200
Content-type fix, star resource type, 500 status code
---
serverless-microsling/lib/openwhisk-renderer.js | 4 +++-
serverless-microsling/lib/render.js | 4 ++--
serverless-microsling/microsling.js | 6 +++---
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/serverless-microsling/lib/openwhisk-renderer.js b/serverless-microsling/lib/openwhisk-renderer.js
index 5ac5259..d703607 100644
--- a/serverless-microsling/lib/openwhisk-renderer.js
+++ b/serverless-microsling/lib/openwhisk-renderer.js
@@ -31,7 +31,9 @@ const getActionInfo = async (resourceType, extension) => {
ow.actions.list()
.then(actions => {
const act = actions.find(act => {
- return resourceType == getAnnotation(act, 'sling:resourceType') && extension == getAnnotation(act, 'sling:extensions')
+ const rtAnnotation = getAnnotation(act, 'sling:resourceType');
+ return ('*' == rtAnnotation || resourceType == rtAnnotation)
+ && extension == getAnnotation(act, 'sling:extensions');
})
let result;
if(act) {
diff --git a/serverless-microsling/lib/render.js b/serverless-microsling/lib/render.js
index 91fcaf9..6d4bca0 100644
--- a/serverless-microsling/lib/render.js
+++ b/serverless-microsling/lib/render.js
@@ -55,7 +55,7 @@ async function render(context) {
}
const rendererInfo = await selectRendererInfo(resourceType, extension);
if(context.debug) {
- console.log(rendererInfo);
+ console.log(`rendererInfo: ${JSON.stringify(rendererInfo, 2, null)}`);
}
if(!rendererInfo) {
throw Error(`Renderer not found for ${resourceType} extension ${extension}`);
@@ -66,7 +66,7 @@ async function render(context) {
}
context.response.body = rendered.output;
context.response.headers = {
- 'Content-Type': rendererInfo.contentType
+ 'Content-Type': rendererInfo.info.contentType
};
return context;
diff --git a/serverless-microsling/microsling.js b/serverless-microsling/microsling.js
index c9de1b9..629cf38 100644
--- a/serverless-microsling/microsling.js
+++ b/serverless-microsling/microsling.js
@@ -29,7 +29,7 @@ function main (params) {
debug: params.debug
};
- return new Promise(function (resolvePromise) {
+ return new Promise(function (resolvePromise, reject) {
if(context.debug) console.log(`start: ${JSON.stringify(context, 2, null)}`);
resolveContent(context)
.then(context => {
@@ -42,9 +42,9 @@ function main (params) {
})
.catch(e => {
if(e.httpStatus) {
- return resolvePromise({ status: e.httpStatus, body: e.message});
+ return resolvePromise({ statusCode: e.httpStatus, body: e.message});
} else {
- throw e;
+ return resolvePromise({ statusCode: 500, body: `${e.stack}\n`});
}
})
})
[sling-whiteboard] 02/02: Markdown renderer action
Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit 387949128e32557aac796da4543346e73288f49c
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jul 26 13:46:17 2019 +0200
Markdown renderer action
---
serverless-microsling/install | 14 ++++++--
.../rendering-actions/markdown-default.js | 40 ++++++++++++++++++++++
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/serverless-microsling/install b/serverless-microsling/install
index eccbccc..c4b8e50 100755
--- a/serverless-microsling/install
+++ b/serverless-microsling/install
@@ -18,7 +18,17 @@ echo Preparing $ZIP ... \
&& wsk action update $ACTION $ZIP --web true --kind nodejs:10 --param debug true -a provide-api-key true
echo "Installing rendering actions..."
-wsk action update somedoc-rendering rendering-actions/somedoc-html.js -a sling:resourceType microsling/somedoc -a sling:extensions html
+wsk action update somedoc-html rendering-actions/somedoc-html.js -a sling:resourceType microsling/somedoc -a sling:contentType text/html -a sling:extensions html
+wsk action update markdown-default rendering-actions/markdown-default.js -a sling:resourceType '*' -a sling:contentType text/markdown -a sling:extensions md
-echo "Microsling is available at at $(wsk -i action get $ACTION --url | grep http)"
+export URL=$(wsk -i action get $ACTION --url | grep http)
+echo "Microsling is available at at $URL"
+echo "Interesting test URLs are:"
+for f in demo/index demo/docs/somedoc
+do
+ for x in json txt html md
+ do
+ echo "open $URL/$f.$x"
+ done
+done
diff --git a/serverless-microsling/rendering-actions/markdown-default.js b/serverless-microsling/rendering-actions/markdown-default.js
new file mode 100644
index 0000000..a36c5f1
--- /dev/null
+++ b/serverless-microsling/rendering-actions/markdown-default.js
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2019 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /* eslint-disable no-console */
+function main (params) {
+ const resource = params.resource || { testing:42, thefunction:'here'};
+ let result = '';
+ let heading = '===';
+ Object.keys(resource).forEach(key => {
+ result += `${key}\n${heading}\n${resource[key]}\n\n`;
+ heading = '---';
+ })
+ return { output: result };
+}
+
+if (require.main === module) {
+ const input = {
+ resource: {
+ title: 'cmdline title',
+ body: 'cmdline body',
+ something: 'else',
+ }
+ };
+ console.log(JSON.stringify(main(input), 2, null));
+}
+
+module.exports.main = main
\ No newline at end of file