Skip to content

Support prerendered apps - #147

Closed
evoactivity wants to merge 2 commits into
ember-cli-deploy:masterfrom
evoactivity:prerenderred-support
Closed

evoactivity wants to merge 2 commits into
ember-cli-deploy:masterfrom
evoactivity:prerenderred-support

Conversation

@evoactivity

Copy link
Copy Markdown

What Changed & Why

  • Uses a glob pattern to find all index.html files
  • Loops over list and uploads each file to redis
  • Uses the directory structure as part of the redis key

Related issues

Fixes #132

PR Checklist

  • Add tests
  • Add documentation

@lukemelia

@evoactivity evoactivity changed the title Support prerenderred apps Support prerendered apps Sep 1, 2023
@evoactivity

evoactivity commented Sep 26, 2023 •

Copy link
Copy Markdown
Author

I've been using this successfully with this code to fetch the correct page

import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
import type { RequestContract } from '@ioc:Adonis/Core/Request';
import Redis from '@ioc:Adonis/Addons/Redis';

/**
 * Computes the key based on request's query string.
 * Defaults to the current key from Redis if not provided in the query string.
 */
async function computeKey(request: RequestContract): Promise<string> {
  const { revision } = request.qs();
  return revision || (await Redis.get(`web-app:index:current`));
}

/**
 * Normalizes the URL for consistent lookup.
 * Strips leading and trailing slashes and appends ':index' as a suffix.
 */
function normalizeUrl(url: string): string {
  const strippedUrl = url.replace(/^\/|\/$/g, '');
  return strippedUrl === '' ? 'index' : `${strippedUrl}:index`;
}

export default class EmberWebController {
  public async index({ request, response }: HttpContextContract) {
    const key = await computeKey(request);
    const normalizedUrl = normalizeUrl(request.url());

    // Attempt to retrieve the HTML for the specified URL and key.
    const htmlKey = `web-app:${normalizedUrl}:${key}`;
    if (await Redis.exists(htmlKey)) {
      const html = await Redis.get(htmlKey);
      return response.ok(html);
    }

    // Fallback to retrieve the default HTML for the key.
    const defaultHtml = await Redis.get(`web-app:index:${key}`);
    return response.ok(defaultHtml);
  }
}

@lukemelia

Copy link
Copy Markdown
Contributor

Thanks for this, @evoactivity, and for sharing how you're using it in production. Sorry it sat for so long. I'm closing it as part of a cleanup of stale PRs: the repo is switching from yarn to pnpm, and this PR mixes the feature with a Prettier reformat of the tests and a full yarn.lock rewrite. If you're still interested in prerendered-app support (#132), a fresh PR against current master with just the feature, tests and README docs would be very welcome.

@lukemelia lukemelia closed this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prember / Multiple File Support

2 participants