You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check for 404 before redirecting on no-extension paths (#972)
* Check for 404 before redirecting on no-extension paths
The commit improves routing logic by checking if a path would result in
a 404
fixes#971 before adding a
trailing slash. This prevents unnecessary redirects when a custom 404
handler exists.
* Fix test function signature formatting in routing module (#973)
Co-authored-by: Cursor Agent <[email protected]>
* Simplify path resolution and redirect logic
The shorter code more clearly handles finding files with .sql extensions
and decides whether to add trailing slashes based on index file
presence.
* clippy
---------
Co-authored-by: Cursor Agent <[email protected]>
INSERT INTO blog_posts (title, description, icon, created_at, content)
3
+
VALUES
4
+
(
5
+
'File-based routing in SQLPage',
6
+
'Understanding how SQLPage maps URLs to files and handles errors',
7
+
'route',
8
+
'2025-07-28',
9
+
'
10
+
SQLPage uses a simple file-based routing system that maps URLs directly to SQL files in your project directory.
11
+
No complex configuration is needed. Just create files and they become accessible endpoints.
12
+
13
+
This guide explains how SQLPage resolves URLs, handles different file types, and manages 404 errors so you can structure your application effectively.
14
+
15
+
## How SQLPage Routes Requests
16
+
17
+
### 1. Site Prefix Handling
18
+
19
+
If you''ve configured a [`site_prefix`](/your-first-sql-website/nginx) in your settings,
20
+
SQLPage will redirect all requests that do not start with the prefix to `/<site_prefix>`.
21
+
22
+
### 2. Path Resolution Priority
23
+
24
+
**Directory requests (paths ending with `/`)**: SQLPage looks for an `index.sql` file in that directory and executes it if found.
25
+
26
+
**Direct SQL file requests (`.sql` extension)**: SQLPage executes the requested SQL file if it exists.
27
+
28
+
**Static asset requests (other extensions)**: SQLPage serves files like CSS, JavaScript, images, or any other static content directly.
29
+
30
+
**Clean URL requests (no extension)**: SQLPage first tries to find a matching `.sql` file. If that doesn''t exist but there''s an `index.sql` file in a directory with the same name, it redirects to the directory path with a trailing slash.
31
+
32
+
### Error Handling
33
+
34
+
When, after applying each of the rules above in order, SQLPage can''t find a requested file,
35
+
it walks up your directory structure looking for [custom `404.sql` files](/your-first-sql-website/custom_urls).
36
+
37
+
## Dynamic Routing with SQLPage
38
+
39
+
SQLPage''s file-based routing becomes powerful when combined with strategic use of 404.sql files to handle dynamic URLs. Here''s how to build APIs and pages with dynamic parameters:
40
+
41
+
### Product Catalog with Dynamic IDs
42
+
43
+
**Goal**: Handle URLs like `/products/123`, `/products/abc`, `/products/new-laptop`
0 commit comments