Skip to content

Load and cache index.html using GCP PubSub, works great with ember-cli-deploy

Notifications You must be signed in to change notification settings

knownasilya/index-html-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

index-html-loader

Load index.html from some source and compile it arbitrary data using handlebars. Subsequent requests will use the cache. Cache will be reset and prewarmed when the subscription is triggered in GCP PubSub.

This library works great with ember-cli-deploy and specifically the following plugins:

Example

import setupLoader from 'index-html-loader';
import pkg from './package.json';

const pubsubOptions = { /* ... */ };
const indexHtml = setupLoader({
  project: pkg.name,
  version: pkg.version,
  env: process.env.NODE_ENV,
  // Make sure each pod is invalidated in kubernetes
  subscriptionPostfix: process.env.GCP_POD_ID,
  pubsubOptions,
  findRevision: async (project, revisionId) => {
    return await loadHtml(project, revisionId);
  }
});

router.get('/*', async function (req, res) {
  let data = await loadSomeData();
  let html = await indexHtml.load(data, req.query.revisionKey);

  res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
  res.header('Expires', '-1');
  res.header('Pragma', 'no-cache');
  res.send(html);
});

Debug

You can log details from this library by adding the following environment variable to your start/watch script.

DEBUG=index-html-loader npm start

About

Load and cache index.html using GCP PubSub, works great with ember-cli-deploy

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published