Reference sections
Reference › File types
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:
| Extension | Type | Behaviour |
|---|---|---|
| .page.js|.ts | Dynamic 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.md | Dynamic 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|.ts | HTTP route | Served 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|.ts | WebSocket route | Served 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|.ts | A component file, returns HTML | Ignored by router. |
| .layout.js|.ts | Layout component, returns HTML | Ignored by router. |
| .fragment.js|.ts | A fragment file, returns HTML | Ignored by router. |
| .fragment.html | An HTML fragment file | Ignored by router. |
| .fragment.css | A CSS fragment file | Ignored by router. |
| .fragment.md | A Markdown fragment file | Ignored by router. |
| .script.js|.ts | Server-side script file | Ignored 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|.ts | Server-side styles file | Ignored by router. Useful for including server-side CSS (in JS). File is not accessible from the client. |
| .client.js|.ts | Page client script | Served as a static file; loaded as a module by the page with the same name. |
| Other (.html, .css, .js, .jpg, .gif, etc.) | Static files | Any 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.)