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

Commit

Permalink
fix(google): use default service when GOOGLE_DOCS_ROOT is not availab…
Browse files Browse the repository at this point in the history
…le (#74)

fixes #73
  • Loading branch information
tripodsan authored Sep 11, 2019
1 parent 0349c63 commit e401f71
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:

- run:
name: Deploy to Adobe I/O Runtime
command: npx hlx deploy --default GOOGLE_DOCS_ROOT $GOOGLE_DOCS_ROOT | cat
command: npx hlx deploy | cat

- run:
name: Publish to Fastly
Expand Down
14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,4 @@ The project requires some extensions of the default VCL provided by Helix. The p
hlx publish --custom-vcl='vcl/extensions.vcl'
```

The patched version of the 3 subroutines adds the parsing of the host url to extract the content owner / repo that would override the one stored in the Fastly dictionnary.


## Manual testing with google docs support

The google docs support is experimental and requires the `GOOGLE_DOCS_ROOT` action param to be set.
This is done automatically during CI, but when testing locally it needs to be specified as action param:

eg:
```
$ export GOOGLE_DOCS_ROOT=https://script.google.com/macros/s/xxxxx/exec
$ hlx up --dev-default GOOGLE_DOCS_ROOT $GOOGLE_DOCS_ROOT
```
The patched version of the 3 subroutines adds the parsing of the host url to extract the content owner / repo that would override the one stored in the Fastly dictionary.
10 changes: 2 additions & 8 deletions src/fetch-google.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@ async function fetch(context, action, resourcePath, rootId) {
const uri = `${secrets.REPO_RAW_ROOT}?path=${encodeURIComponent(resourcePath)}&rootId=${encodeURIComponent(rootId)}&src=${encodeURIComponent(source)}&rid=${encodeURIComponent(requestId)}`;
const options = {
uri,
json: true,
json: false,
timeout,
time: true,
followAllRedirects: true,
};

logger.info(`fetching Markdown from ${options.uri}`);
try {
const resp = await client(options);
if (resp.statusCode === 200) {
content.body = resp.body;
} else {
logger.info(`failed loading from google docs: ${resp.statusCode}`);
// do not throw error in order to allow resource merging in github repository
}
content.body = await client(options);
} catch (e) {
if (e.statusCode === 404) {
logger.error(`Could not find Markdown at ${options.uri}`);
Expand Down
6 changes: 1 addition & 5 deletions src/html.pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ module.exports.before = {
logger.info(`mount point type '${mp.type}' not supported.`);
return;
}
if (!secrets.GOOGLE_DOCS_ROOT) {
logger.warn('google docs mountpoint needs a configured GOOGLE_DOCS_ROOT but is missing.');
return;
}
if (!mp.id) {
logger.warn('google docs mountpoint needs id');
return;
Expand All @@ -99,7 +95,7 @@ module.exports.before = {
logger.info(`relPath=${relPath}`);
const oldRaw = secrets.REPO_RAW_ROOT;
const oldTimeout = secrets.HTTP_TIMEOUT;
secrets.REPO_RAW_ROOT = secrets.GOOGLE_DOCS_ROOT;
secrets.REPO_RAW_ROOT = secrets.GOOGLE_DOCS_ROOT || 'https://adobeioruntime.net/api/v1/web/helix/helix-services/gdocs2md@latest';
// ump the timeout a bit, since the google docs script might take a while to render
secrets.HTTP_TIMEOUT = 10000;
try {
Expand Down

0 comments on commit e401f71

Please sign in to comment.