# the renderer's pages in front of the svfe SPA. include inside the knot's server block,
# after its /xrpc/ locations. <out> is svfe-pages --out, <build> svfe's client build/
location / {
root <out>/www;
# pages are stored gzipped next to an empty stub, so try_files sees the name
gzip_static always;
gunzip on;
# a page changes with every render that touches it: revalidate (ETag) on every use
add_header Cache-Control "no-cache";
# a later page of a list is <list>~page-N.html: the uri is rewritten to that name and
# comes back through here (rewrite last is what's safe inside an if). one the renderer
# didn't keep goes to the SPA, never to page 1
if ($arg_page ~ "^0*([2-9]|[1-9][0-9]+)$") {
set $page $1;
rewrite ^(.*)$ "$1~page-$page?" last;
}
# a file or folder page is <path>.html, the repo's front page <repo>/index.html
try_files $uri.html $uri/index.html @spa;
}
# what all of a repo's pages share, named by content, so it never changes under a name
location ~ ^/[^/]+/[^/]+/_shared/ {
root <out>/www;
gzip_static always;
gunzip on;
default_type application/json;
expires max;
try_files $uri =404;
}
# the newest copy under a stable name, for pages the renderer left to the SPA, and a user's
# routes file at <owner>/_latest/: revalidated on every use, so a new render shows up at once
location ~ ^/[^/]+(/[^/]+)?/_latest/ {
root <out>/www;
gzip_static always;
gunzip on;
default_type application/json;
add_header Cache-Control "no-cache";
try_files $uri =404;
}
location @spa {
root <build>;
gzip_static on;
add_header Cache-Control "no-cache";
try_files $uri /index.html;
}
# version.json, which a page polls to learn of a new build
location /_app/ {
root <build>;
gzip_static on;
add_header Cache-Control "no-cache";
}
# a page loads the chunks of the build that rendered it: the renderer keeps those of every
# build a served page was rendered by, the newest build has its own
location ^~ /_app/immutable/ {
root <out>/www;
gzip_static on;
expires max;
try_files $uri @immutable;
}
location @immutable {
root <build>;
gzip_static on;
expires max;
}