KScript docs
EN

Web pages

Routing

The file a URL serves comes from its path. /people serves people.html, people.md or people/index.html. A folder or file name in brackets matches any value, so /people/42 can match people/[id].html, where the value is $request.params.id.

Files and folders whose names start with _ or ., and KScript sources (.kscript, .ks.xml and any other .xml), are never served. Nor is what a project is built and run with: Dockerfile, Makefile, package.json, package-lock.json, node_modules, README.md, databases (.sqlite, .sqlite3, .db) and .log files. A file of one of those kinds that is meant to be downloaded goes in the public folder (serve.public), which is served as it is. An address with a backslash or an empty part (/\example.com, //example.com) names no page and no route, because browsers read those as another site's address. A symbolic link is followed to where it really leads: a link inside the site folder to a file or folder outside it, or to one of the parts above, is not served, and pages and routes can't read or write through it either. A link to another part of the site works as usual. _404.html is used for missing pages, and may use layouts, components and live blocks like any page.

Pictures, fonts and other files that never change can live in a folder of their own: set "public": "public" in the serve section of kscript.json, and public/brand/logo.png is served at /brand/logo.png. The folder is relative to kscript.json, so it may sit beside the site folder rather than in it. A file in the site folder wins over one with the same address in the public folder, and nothing in the public folder is run as a page: an .html file there is sent as it is.

Every file is sent with Last-Modified and an ETag, so a browser that already has it asks whether it changed and gets 304 Not Modified, with no body, when it hasn't.