Infrakinetic Developers

Server snippets: PHP, Node, Python

For custom sites, Express, Django, Laravel and the like. Each snippet fetches the page for the current address, caches it on disk with its version tag, and serves the last good copy for up to 7 days if our API cannot be reached.

Set INFRAKINETIC_RENDER_KEY and INFRAKINETIC_SITE_URL in your server's environment. Download: infrakinetic.php, infrakinetic.mjs, infrakinetic.py.

PHP

<?php require __DIR__ . '/infrakinetic.php';
$page = infrakinetic_page();            // null: not ours
if (!$page) { http_response_code(404); include '404.php'; exit; }
?>
<html><head><?= $page['head_html'] ?></head>
<body><?php include 'header.php'; ?>
<?= $page['html'] ?>
<?php include 'footer.php'; ?>
<?= infrakinetic_hydrate_tag($page) ?></body></html>

Node (Express)

import { infrakineticPage, hydrateTag, purgeEndpoint } from "./infrakinetic.mjs";

app.get(["/careers", "/careers/*"], async (req, res, next) => {
  const page = await infrakineticPage(req.path);
  if (!page) return next();
  res.render("layout", { head: page.head_html, body: page.html + hydrateTag(page) });
});
app.post("/infrakinetic/purge", express.text({ type: "*/*" }), purgeEndpoint);

Or install @infrakinetic/delivery, which adds an in-memory cache, the sitemap and the change feed, and runs on edge runtimes too.

Python (Django)

from django.http import Http404
from django.shortcuts import render
from infrakinetic import infrakinetic_page, hydrate_tag

def careers(request, rest=""):
    page = infrakinetic_page(request.path)
    if page is None:
        raise Http404
    return render(request, "infrakinetic.html", {"page": page, "hydrate": hydrate_tag(page)})

Keeping pages fresh

Each copy is refreshed after a minute with a cheap "has it changed?" request. To clear changed pages at once, poll GET /changes every few minutes and pass each item to the snippet's purge function (infrakinetic_purge in PHP). Each snippet also has a signed purge endpoint that checks Infrakinetic's webhook signature against the raw body, refuses anything older than five minutes, and accepts either of two secrets while one is being rotated.