Kitten

Reference sections

Kitten doesn’t force you to put different types of routes into predefined folders. Instead, it uses file extensions to know how to handle different routes and other code and assets.

Here is a list of the main file types Kitten handles and how it handles them:

ExtensionTypeBehaviour
.page.js|.tsDynamic page (JS|TS)JavaScript/TypeScript route that is rendered into HTML and served in response to a HTTP GET request for the specified path.
.page.mdDynamic page (Markdown)Markdown route with optional front matter that supports JavaScript imports and the use of Kitten components and fragments in Markdown that is rendered into HTML and served in response to a HTTP GET request for the specified path.
.post.js|.ts, .get.js|.ts, .put.js|.ts, .head.js|.ts, .patch.js|.ts, .options.js|.ts, .delete.js|.ts, .trace.js|.tsHTTP routeServed in response to an HTTP request for the specified method and path. (A .connect.js or .connect.ts file stops Kitten at start-up, as Node never passes CONNECT requests to routes.)
.socket.js|.tsWebSocket routeServed in response to a WebSocket request for exactly the specified path. Only file type to keep part of its file extension in its route pattern (e.g., the file /my.socket.js exists at the URL fragment /my.socket.)
.component.js|.tsA component file, returns HTMLIgnored by router.
.layout.js|.tsLayout component, returns HTMLIgnored by router.
.fragment.js|.tsA fragment file, returns HTMLIgnored by router.
.fragment.htmlAn HTML fragment fileIgnored by router.
.fragment.cssA CSS fragment fileIgnored by router.
.fragment.mdA Markdown fragment fileIgnored by router.
.script.js|.tsServer-side script fileIgnored by router. Useful for including server-side JavaScript modules. File is not accessible from the client. Put server-only helpers here. Kitten serves any .js or .ts file that isn’t listed in this table to the browser.
.styles.js|.tsServer-side styles fileIgnored by router. Useful for including server-side CSS (in JS). File is not accessible from the client.
.client.js|.tsPage client scriptServed as a static file; loaded as a module by the page with the same name.
Other (.html, .css, .js, .jpg, .gif, etc.)Static filesAny other files in your project apart from the ones listed above are served as static files.

You do not have to do anything special to serve static files with Kitten. It is, first and foremost, a web server, after all. Any file that’s in your project folder that isn’t a hidden file or in a hidden folder and isn’t a special Kitten file (e.g., .page.js, .socket.js, .post.js, etc.), will be served as a static file.

If you have symlinks with extensions that Kitten knows how to route, your symlinks will get routed as if they were regular files.

e.g., You have a README.md file and you want the index of your page to display it without redundancy. Create a symlink inside your project folder:

ln -s ./README.md index.page.md

Now, when you hit the index of your site, you will see the README file.

Kitten will only route symlinks that point to files in your project directory or to folders under it, not outside. (Otherwise, it would open the door to a whole family of potential security issues.)

Like this? Fund us!

Small Technology Foundation is a tiny, independent not-for-profit.

We exist in part thanks to patronage by people like you. If you share our vision and want to support our work, please become a patron or donate to us today and help us continue to exist.