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 .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ jobs:

- name: Deploy to Cloudflare Workers (production)
if: github.ref_name == 'main'
uses: cloudflare/wrangler-action@v4
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

- name: Deploy to Cloudflare Workers (stage)
if: github.ref_name == 'stage'
uses: cloudflare/wrangler-action@v4
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Expand Down
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,17 @@ Prerequisites:

This worker performs all content operations via [da-admin](https://github.com/adobe/da-admin). For local development, you will also need to check out and run da-admin locally.

One read of config.aem.page, pipeline scope, answers existence, head.html and `contentSource`. Its url names the store.

The config service needs a shared secret, so local development points at `dev/lookup-shim.js` instead. Add the org and site to its `SITES` table. A site missing from the table is answered 404. A source url on api.aem.live reads as source-bus.

To run da-universal locally:

1. Clone this repo to your computer.
1. Run `npm install`
1. Use `npx wrangler login` if not done before. Walk through the steps in browser.
1. In a terminal, run `npm run dev:lookups` to start the stand-in lookups on port 4713.
1. In a second terminal, run `npm run dev` in this repo's folder.
1. In a terminal, run `npm run dev` this repo's folder.
1. The da-ue service API is available via https://localhost:4712

Running against the stand-in warns that `HLX_CONFIG_SERVICE_TOKEN` is missing, which it is, and nothing asks for it.

with the shared secret, use `npm run dev` at the real services instead of the stand-in. Put `HLX_CONFIG_SERVICE_TOKEN="<token>"` in `.dev.vars.dev`, which is gitignored, and run `npm run dev -- --var HLX_CONFIG_SERVICE:https://config.aem.page`.

### Run on stage

You can deploy da-universal on Cloudflare stage via `npm run deploy:stage` to test it in a real worker environment.
You can deploy da-universal on Cloudflare stage via `npm deploy:stage` to test it in a real worker environment.

## Customer documentation
https://docs.da.live/developers/reference/universal-editor
47 changes: 0 additions & 47 deletions dev/lookup-shim.js

This file was deleted.

9 changes: 0 additions & 9 deletions dev/lookup-shim.toml

This file was deleted.

2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { defineConfig, globalIgnores } from '@eslint/config-helpers';
import { recommended, source, test } from '@adobe/eslint-config-helix';

export default defineConfig([
globalIgnores(['.vscode/*', '**/.wrangler/**', 'coverage/*']),
globalIgnores(['.vscode/*', '.wrangler/*', 'coverage/*']),
{
languageOptions: {
...recommended.languageOptions,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"deploy": "wrangler deploy",
"deploy:stage": "wrangler deploy --env stage",
"dev": "wrangler dev --local-protocol https --env dev",
"dev:lookups": "wrangler dev -c dev/lookup-shim.toml",
"start": "wrangler dev --local-protocol https --env dev",
"test": "c8 mocha --spec=test/**/*.test.js",
"lint": "eslint ."
Expand Down
12 changes: 3 additions & 9 deletions src/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function getHandler({ req, env, daCtx }) {
if (path.startsWith('/favicon.ico')) return get404();
if (path.startsWith('/robots.txt')) return getRobots();

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

const resourceRegex = /\.(css|js|js\.map|json|xml|woff|woff2|otf|ttf|plain\.html|html)$/i;
if (resourceRegex.test(path)) {
Expand All @@ -35,14 +35,8 @@ export default async function getHandler({ req, env, daCtx }) {
handleAEMProxyRequest({ req, env, daCtx }),
]);

// logs a rejection rather than rethrowing it, since the other read may still answer
const settled = (result, read) => {
if (result.status === 'fulfilled') return result.value;
console.error(`${read} threw on ${path}`, result.reason);
return undefined;
};
const storeRes = settled(daSourceGetRes, 'the store read');
const aemRes = settled(aemProxyRes, 'the aem proxy');
const storeRes = daSourceGetRes.status === 'fulfilled' ? daSourceGetRes.value : undefined;
const aemRes = aemProxyRes.status === 'fulfilled' ? aemProxyRes.value : undefined;

let response;
if (storeRes?.status === 200) {
Expand Down
4 changes: 0 additions & 4 deletions src/responses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ export function post503(message = '', error = '') {
});
}

export function post404(message = '') {
return daResp({ body: message, status: 404, contentType: 'text/plain; charset=utf-8' });
}

// RFC 9110 requires an Allow header on a 405, and reads are what is left once the write is gone.
export function post405(message = '') {
return daResp({
Expand Down
8 changes: 4 additions & 4 deletions src/routes/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import { daResp, get401 } from '../responses/index.js';
import { isTrustedOrigin } from '../utils/constants.js';

async function exchangeSiteToken(env, org, site, accessToken) {
async function exchangeSiteToken(org, site, accessToken) {
try {
const response = await fetch(new URL('/auth/adobe/exchange', env.AEM_API), {
const response = await fetch('https://admin.hlx.page/auth/adobe/exchange', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -48,7 +48,7 @@ async function exchangeSiteToken(env, org, site, accessToken) {
}
}

export async function getCookie({ req, env, daCtx }) {
export async function getCookie({ req, daCtx }) {
const { headers } = req;

if (!isTrustedOrigin(headers.get('Origin'))) return daResp({ body: '403 Forbidden', status: 403, contentType: 'text/plain' });
Expand All @@ -67,7 +67,7 @@ export async function getCookie({ req, env, daCtx }) {

// Try to exchange for site token
if (org && site && !daCtx.siteToken) {
const siteTokenData = await exchangeSiteToken(env, org, site, cookieValue);
const siteTokenData = await exchangeSiteToken(org, site, cookieValue);
if (siteTokenData) {
// Calculate Max-Age based on token expiry time (siteTokenExpiry is in milliseconds)
const now = Date.now();
Expand Down
Loading