How SQLPage maps URLs to SQL files and handles 404 errors
SQLPage uses a file-based routing system that maps HTTP request URLs directly to .sql files in your web root directory. This approach is similar to traditional web servers but specifically designed for SQL-driven applications.
GET /nonexistent HTTP/1.1→ Not found, checks for 404.sql in current directory→ Executes: ./404.sqlGET /admin/missing HTTP/1.1→ Not found in /admin/→ Checks: admin/404.sql (found!)→ Executes: admin/404.sqlGET /admin/api/missing HTTP/1.1→ Not found in /admin/api/→ Checks: admin/api/404.sql (not found)→ Checks: admin/404.sql (found!)→ Executes: admin/404.sql
-- Set 404 status codeSELECT 'http_header' as component, 'Status' as header, '404 Not Found' as value;SELECT 'hero' as component, 'Page Not Found' as title, 'The page you requested does not exist.' as description, 'Sorry about that!' as description_md;SELECT 'button' as component;SELECT '/' as link, 'Go Home' as title, 'home' as icon;-- Log 404 for analyticsINSERT INTO page_views (path, status_code, timestamp)VALUES ($path, 404, CURRENT_TIMESTAMP);
Query strings are preserved and accessible via SQL parameters:
GET /users?id=42&filter=active HTTP/1.1
users.sql
SELECT 'card' as component;SELECT name as title, email as descriptionFROM usersWHERE id = $id -- Gets value '42' AND status = $filter; -- Gets value 'active'
Query parameters are available via $param syntax. See SQL Parameters for details.
blog/├── index.sql # List all posts├── post.sql # Single post view├── category/│ ├── index.sql # List categories│ └── view.sql # Posts in category└── 404.sql
-- URL: /blog/post?slug=my-first-postSELECT 'http_header' as component, 'Status' as header, CASE WHEN $slug IS NULL THEN '400 Bad Request' ELSE '200 OK' END as value;SELECT 'article' as component;SELECT title, content, published_dateFROM blog_postsWHERE slug = $slug;-- If no post found, show 404SELECT 'redirect' as component, '/blog/404' as linkWHERE NOT EXISTS ( SELECT 1 FROM blog_posts WHERE slug = $slug);
-- Redirect based on Accept-Language headerSELECT 'redirect' as component, CASE WHEN $http_accept_language LIKE '%fr%' THEN '/fr/' ELSE '/en/' END as link;