Skip to content
Draft
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
15 changes: 15 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"hast-util-format": "^1.1.0",
"hast-util-from-html": "^2.0.3",
"hast-util-heading": "^3.0.0",
"hast-util-is-element": "^3.0.0",
"hast-util-minify-whitespace": "^1.0.1",
"hast-util-select": "^6.0.3",
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import { get404, getRobots } from '../responses/index.js';
import { handleAEMProxyRequest } from '../routes/aem-proxy.js';
import { getCookie } from '../routes/cookie.js';
import { daSourceGet } from '../routes/da-admin.js';
import { handleUEJsonRequest } from '../routes/ue-definitions.js';

export default async function getHandler({ req, env, daCtx }) {
const { path } = daCtx;

if (!daCtx.site) return get404();
if (path.startsWith('/favicon.ico')) return get404();
if (path.startsWith('/robots.txt')) return getRobots();

if (path.startsWith('/gimme_cookie')) return getCookie({ req });
if (path.startsWith('/.da-ue')) return handleUEJsonRequest({ req, env, daCtx });

const resourceRegex = /\.(css|js|png|jpg|jpeg|webp|gif|svg|ico|json|xml|woff|woff2|plain\.html)$/i;
if (resourceRegex.test(path)) {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/da-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ export async function daSourceGet({ req, env, daCtx }) {
if (daAdminResp && daAdminResp.status === 200) {
// enrich stored content with HTML header and UE attributes
const originalBodyHtml = await daAdminResp.text();
const responseHtml = await prepareHtml(daCtx, aemCtx, originalBodyHtml, headHtml);
const responseHtml = await prepareHtml(env, daCtx, aemCtx, originalBodyHtml, headHtml);
response.body = responseHtml;
} else {
// enrich default template with HTML header and UE attributes
const templateHtml = await getPageTemplate(env, daCtx, aemCtx, headHtml);
const responseHtml = await prepareHtml(daCtx, aemCtx, templateHtml, headHtml);
const responseHtml = await prepareHtml(env, daCtx, aemCtx, templateHtml, headHtml);
response.body = responseHtml;
}

Expand Down
54 changes: 54 additions & 0 deletions src/routes/ue-definitions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import { UE_JSON_FILES } from '../utils/constants.js';
import { get404 } from '../responses/index.js';
import { fetchBlockLibrary, getComponentDefinitions, getComponentFilters, getComponentModels } from '../ue/definitions.js';

Check failure on line 15 in src/routes/ue-definitions.js

View workflow job for this annotation

GitHub Actions / Running tests (20.x)

Expected a line break before this closing brace

Check failure on line 15 in src/routes/ue-definitions.js

View workflow job for this annotation

GitHub Actions / Running tests (20.x)

Expected a line break after this opening brace

/**
* Main handler for the DA block library route
*/
export async function handleUEJsonRequest({ req, env, daCtx }) {
// request routing, we only support component-definition.json, component-models.json
// and component-filters.json

// TODO get JSON from KW store, if not found render from block library
const path = new URL(req.url).pathname;
const jsonPath = path.replace('/.da-ue/', '');
if (!UE_JSON_FILES.includes(jsonPath)) {
return get404();
}

const blocks = await fetchBlockLibrary(env, daCtx);

if (path === '/.da-ue/component-definition.json') {
const componentDefinitions = getComponentDefinitions(blocks);
return new Response(
JSON.stringify(componentDefinitions, null, 2),
{
headers: { 'Content-Type': 'application/json' },
},
);
} else if (path === '/.da-ue/component-models.json') {
const componentModels = getComponentModels(blocks);
return new Response(JSON.stringify(componentModels, null, 2), {
headers: { 'Content-Type': 'application/json' },
});
} else if (path === '/.da-ue/component-filters.json') {
const componentFilters = getComponentFilters(blocks);
return new Response(JSON.stringify(componentFilters, null, 2), {
headers: { 'Content-Type': 'application/json' },
});
}

return get404();
}
Loading
Loading