Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/helpers/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import normalizeCharset from '../utils/charset.js';
* Builds a source response
* @param {*} key
*/
export function sourceRespObject(daCtx) {
export function sourceRespObject(env, daCtx) {
const {
org, site, isFile, pathname, aemPathname,
} = daCtx;

const obj = {
source: {
editUrl: `https://da.live/${isFile ? 'edit#/' : ''}${org}${pathname}`,
contentUrl: `https://content.da.live/${org}${pathname}`,
contentUrl: `${env.DA_CONTENT}/${org}${pathname}`,
},
};

Expand Down
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface Env {
S3_SECRET_ACCESS_KEY: string;
IMS_ORIGIN: string;
AEM_BUCKET_NAME: string;
// base URL for source content links (eg https://content.da.live)
DA_CONTENT: string;
// shared secret used as authorization when invoking the collab service (eg for syncadmin)
COLLAB_SHARED_SECRET: string;
DA_OPS_IMS_ORG: string;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default async function putObject(env, daCtx, obj) {
await client.send(command);
}

const body = sourceRespObject(daCtx);
const body = sourceRespObject(env, daCtx);
return {
body: JSON.stringify(body), status, contentType: 'application/json', metadata, etag,
};
Expand Down
40 changes: 39 additions & 1 deletion test/helpers/source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/
import assert from 'node:assert';
import { putHelper } from '../../src/helpers/source.js';
import { putHelper, sourceRespObject } from '../../src/helpers/source.js';

import env from '../utils/mocks/env.js';

Expand All @@ -19,6 +19,44 @@ const daCtx = { org: 'cq', key: 'geometrixx/hello.html', propsKey: 'geometrixx/h
const MOCK_URL = 'https://da.live/source/cq/geometrixx/hello';

describe('Source helper', () => {
describe('sourceRespObject', () => {
it('builds contentUrl from env.DA_CONTENT', () => {
const obj = sourceRespObject(
{ DA_CONTENT: 'https://stage-content.da.live' },
{ org: 'cq', pathname: '/geometrixx/hello.html' },
);
assert.strictEqual(obj.source.contentUrl, 'https://stage-content.da.live/cq/geometrixx/hello.html');
assert.strictEqual(obj.source.editUrl, 'https://da.live/cq/geometrixx/hello.html');
});

it('uses production DA_CONTENT when provided', () => {
const obj = sourceRespObject(
{ DA_CONTENT: 'https://content.da.live' },
{ org: 'cq', pathname: '/geometrixx/hello.html' },
);
assert.strictEqual(obj.source.contentUrl, 'https://content.da.live/cq/geometrixx/hello.html');
});

it('adds aem urls when site is present', () => {
const obj = sourceRespObject(
{ DA_CONTENT: 'https://content.da.live' },
{
org: 'cq', site: 'geometrixx', pathname: '/index.html', aemPathname: '/index',
},
);
assert.strictEqual(obj.aem.previewUrl, 'https://main--geometrixx--cq.aem.page/index');
assert.strictEqual(obj.aem.liveUrl, 'https://main--geometrixx--cq.aem.live/index');
});

it('uses edit#/ prefix for files', () => {
const obj = sourceRespObject(
{ DA_CONTENT: 'https://content.da.live' },
{ org: 'cq', isFile: true, pathname: '/geometrixx/hello.html' },
);
assert.strictEqual(obj.source.editUrl, 'https://da.live/edit#/cq/geometrixx/hello.html');
});
});

describe('Put success', async () => {
it('Returns null if no content type', async () => {
const req = new Request(MOCK_URL);
Expand Down
2 changes: 1 addition & 1 deletion test/it/it-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default (ctx) => describe('Integration Tests: it tests', function () {

let body = await resp.json();
assert.strictEqual(body.source.editUrl, `https://da.live/edit#/${org}/${repo}/${key}`);
assert.strictEqual(body.source.contentUrl, `https://content.da.live/${org}/${repo}/${key}`);
assert.strictEqual(body.source.contentUrl, `https://stage-content.da.live/${org}/${repo}/${key}`);
assert.strictEqual(body.aem.previewUrl, `https://main--${repo}--${org}.aem.page/${key}`);
assert.strictEqual(body.aem.liveUrl, `https://main--${repo}--${org}.aem.live/${key}`);

Expand Down
1 change: 1 addition & 0 deletions test/utils/mocks/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const DA_CONFIG = {
};

const env = {
DA_CONTENT: 'https://stage-content.da.live',
S3_DEF_URL: 'https://s3.com',
S3_ACCESS_KEY_ID: 'an-id',
S3_SECRET_ACCESS_KEY: 'too-many-secrets',
Expand Down
5 changes: 5 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ r2_buckets = [
ENVIRONMENT = "production"
VERSION = "@@VERSION@@"
DA_COLLAB = "https://collab.da.page"
DA_CONTENT = "https://content.da.live"
AEM_BUCKET_NAME = "aem-content"
AEM_ADMIN_MEDIA_API = "https://admin.hlx.page/media"

Expand All @@ -50,6 +51,7 @@ r2_buckets = [
ENVIRONMENT = "stage"
VERSION = "@@VERSION@@-stage"
DA_COLLAB = "https://collab.da.page"
DA_CONTENT = "https://stage-content.da.live"
AEM_BUCKET_NAME = "aem-content-stage"
AEM_ADMIN_MEDIA_API = "https://admin.hlx.page/media"

Expand All @@ -75,6 +77,7 @@ r2_buckets = [
ENVIRONMENT = "ci"
VERSION = "@@VERSION@@-stage"
DA_COLLAB = "https://collab.da.page"
DA_CONTENT = "https://stage-content.da.live"
AEM_BUCKET_NAME = "aem-content-stage"
AEM_ADMIN_MEDIA_API = "https://admin.hlx.page/media"

Expand All @@ -101,6 +104,7 @@ r2_buckets = [
ENVIRONMENT = "dev"
VERSION="0.0.0-dev"
DA_COLLAB = "http://localhost:4711"
DA_CONTENT = "https://stage-content.da.live"
AEM_BUCKET_NAME = "aem-content-stage"
AEM_ADMIN_MEDIA_API = "https://admin.hlx.page/media"

Expand All @@ -126,6 +130,7 @@ r2_buckets = [
ENVIRONMENT = "it"
VERSION="0.0.0-it"
DA_COLLAB = "http://localhost:4711"
DA_CONTENT = "https://stage-content.da.live"
AEM_BUCKET_NAME = "aem-content-local"
AEM_ADMIN_MEDIA_API = "https://admin.hlx.page/media"

Loading