Skip to content

Commit 2e15097

Browse files
committed
refactor(deserve): extract response/static/error, pluggable handler, middleware classes ♻️
- Add body parse caching, request state, and replaceRequest to Context - Add constant-time credential comparison in BasicAuth - Add error response builder and static handler options to Handler and Router - Add stream-based body limit with replaceRequest in BodyLimit middleware - Delegate route scan and pattern creation to Scanner in Handler - Extend Types with ErrorResponseBuilder, HandlerOptions, SecurityHeadersOptions, Session and WebSocket options, StaticHandler - Export Handler, Constant, Error, Response, Redirect, Static, Scanner and type namespace from index - Move response helpers and redirect into dedicated modules; Context.send uses ResponseHelpers - Refactor Constant to class with static allowedExtensions, contentTypes, httpMethods - Refactor middleware to class factories (BasicAuth, BodyLimit, Cors, WebSocket) and wrapMiddleware - Remove SecurityHeaders middleware (replaced by SecHeaders) - Update deno.json with bench/test tasks, compiler options, and publish excludes - Update publish workflow to deno-publish, check only, publish with --allow-dirty - Update README and benchmark README with features, quick start, and run instructions
1 parent 4d4dcdb commit 2e15097

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2773
-1098
lines changed

.github/workflows/ci.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-check:
11+
name: Build Check
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Deno
19+
uses: denoland/setup-deno@v2
20+
with:
21+
deno-version: v2.5.4
22+
23+
- name: Format check
24+
run: deno fmt --check src/
25+
26+
- name: Lint
27+
run: deno lint src/
28+
29+
- name: Type check
30+
run: deno check src/
31+
32+
- name: Test
33+
run: deno test tests/ --allow-read

.github/workflows/publish.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ on:
66
- main
77

88
jobs:
9-
publish:
9+
deno-publish:
10+
name: Deno (JSR)
1011
runs-on: ubuntu-latest
1112
permissions:
1213
contents: read
@@ -18,8 +19,8 @@ jobs:
1819
with:
1920
deno-version: v2.5.4
2021

21-
- name: Run lint and check
22-
run: deno lint src/ && deno check src/
22+
- name: Check package
23+
run: deno check src/
2324

24-
- name: Publish package
25-
run: deno publish
25+
- name: Publish to JSR
26+
run: deno publish --allow-dirty

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Deno
22
.deno/
3+
coverage/
34
deno.lock
45

56
# IDE
@@ -9,3 +10,8 @@ deno.lock
910
# OS
1011
.DS_Store
1112
Thumbs.db
13+
14+
# Vite / Node
15+
.vite/
16+
node_modules/
17+
dist/

CHANGELOG.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Changelog
2+
3+
All notable changes to Deserve. Full commit history in chronological order.
4+
5+
Format inspired by [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6+
7+
---
8+
9+
## [Unreleased]
10+
11+
### 2026-03-07
12+
13+
**Committed**
14+
15+
- `4d4dcdb` style(handler): enforce braces for control statements
16+
- `1c80c4e` feat(deserve): optimize framework for streaming and error handling
17+
18+
**Uncommitted (working tree)**
19+
20+
- **Config:** .gitignore, deno.json
21+
- **Core / refactor:** Constant, Context, Handler, Router, Types, index — cleanup and consolidation
22+
- **New modules:** Error (error response builder, escapeHtml), Redirect, Response (Send helpers), Scanner (file-based routing), Static (static file serving)
23+
- **Middleware:** BasicAuth, BodyLimit, CORS, WebSocket, index — refactor; SecurityHeaders removed → SecHeaders (new); Loaders, Session, Utils (wrapMiddleware) added
24+
- **Docs / meta:** CHANGELOG.md (full commit history)
25+
- **Tests:** context, handler, middleware, router test files
26+
27+
---
28+
29+
## [0.7.0] - 2025-10-30
30+
31+
### 2025-10-30
32+
33+
- `0ff9118` release(docs): mark features as released and update version to 0.7.0
34+
- `583106f` docs(static-file): clarify path extraction and wildcard pattern behavior
35+
- `3675be0` fix(handler): fix route scanning and static file path resolution
36+
- `010597f` fix(docs): configure search at root level
37+
- `36f8336` feat(middleware): add security headers middleware
38+
39+
### 2025-10-29
40+
41+
- `a4c8db8` feat(middleware): add body limit middleware
42+
- `acb560d` feat(middleware): add basic auth and improve error handling
43+
- `ef190fa` feat(docs): restructure documentation with i18n support
44+
- `2812d25` feat(router): simplify constructor and add middleware support
45+
- `5569c43` feat(static): add custom static file serving
46+
47+
### 2025-10-28
48+
49+
- `6fb36b7` refactor(core): migrate to Context-based architecture
50+
51+
### 2025-10-27
52+
53+
- `8a99a21` fix(core): migrate to external router and fix replacement bugs
54+
55+
### 2025-10-26
56+
57+
- `dfd1b35` feat(routing): add case-sensitive routing and filename characters
58+
- `f4416c3` feat(core): add middleware support for DeserveRequest objects
59+
60+
### 2025-10-25
61+
62+
- `81d5822` feat(middleware): add websocket middleware support
63+
- `31f35d7` feat(benchmark): add performance benchmarks documentation
64+
- `984ebad` refactor(router): migrate to FastRouter with radix tree structure
65+
- `cfa06cd` feat(docs): add request body parsing methods and bump version
66+
- `3fdacd9` feat(request): add enhanced request handling with automatic parsing
67+
- `50192b7` refactor(constants): centralize HTTP methods and improve validation
68+
- `8866020` docs(installation): update deno install link
69+
- `18db701` ci(deploy): add nojekyll file creation to vitepress build
70+
- `8e548b3` docs(readme): add installation section
71+
- `1c0cecb` docs(readme): add server configuration link
72+
- `2c43a20` feat(router): enhance serve method with hostname and graceful shutdown
73+
74+
### 2025-10-24
75+
76+
- `d00d938` feat(send): add download response methods
77+
- `5d2821f` docs(rebuild): trigger rebuild for sidebar fix
78+
- `23e8677` docs(config): update documentation and version
79+
- `be7fa66` refactor(docs): move CNAME file location
80+
- `e2f931a` docs(deploy): update build configuration and domain setup
81+
- `9df2495` docs(project): restructure documentation and simplify README
82+
- `8e63612` feat(router): add route module validation
83+
- `aa205ca` feat(utils): add Send utility class for HTTP responses
84+
- `60e6a8d` feat(router): add route-specific middleware and improve documentation
85+
- `de1937b` chore(config): bump version to 0.1.5
86+
- `783b6ba` refactor(router): improve route parsing and scanning logic
87+
- `ba1c5df` feat(router): add HTTPS URL parsing and update version
88+
- `25955bf` fix(router): resolve JSR import path issues and improve route handling
89+
- `99e8696` feat(router): fix module import path resolution
90+
- `6448d7e` feat(static): improve static file serving and documentation
91+
- `e4f471c` fix(router): remove hardcoded path prefix from routes directory
92+
- `c210179` feat(ci): add GitHub Actions workflow and improve router configuration
93+
- `66895d7` feat(router): add static file serving capability
94+
- `09b1e4a` feat(middleware): add built-in CORS middleware and enhanced middleware processing
95+
- `38eaace` feat(error): add error handling middleware
96+
- `aaa14d2` feat(router): initial implementation of file-based routing library
97+
98+
---
99+
100+
[Unreleased]: https://github.com/neabytelab/deserve/compare/v0.7.0...HEAD

README.md

Lines changed: 83 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,100 @@
1-
# Deserve [![License: MIT](https://img.shields.io/badge/License-MIT-red.svg)](LICENSE) [![Deno](https://img.shields.io/badge/Deno-2.5.4-blue)](https://deno.land) [![JSR](https://jsr.io/badges/@neabyte/deserve)](https://jsr.io/@neabyte/deserve)
1+
<div align="center">
2+
3+
# Deserve
24

35
Build HTTP server effortlessly with zero configuration for productivity.
46

5-
## Installation
7+
[![Deno](https://img.shields.io/badge/deno-2.5.4+-000000?logo=deno&logoColor=white)](https://deno.com) [![JSR](https://jsr.io/badges/@neabyte/deserve)](https://jsr.io/@neabyte/deserve) [![CI](https://github.com/NeaByteLab/Deserve/actions/workflows/ci.yaml/badge.svg)](https://github.com/NeaByteLab/Deserve/actions/workflows/ci.yaml) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
8+
9+
</div>
10+
11+
## Features
612

7-
Install [Deno](https://github.com/denoland/deno_install) 2.5.4+ and run `deno init` for new projects.
13+
- **Zero config** — No build step for the server. Point to a routes directory and serve.
14+
- **File-Based Routing** — Drop files in `routes/`; export `GET`, `POST`, etc. File structure is your API.
15+
- **Context** — Request wrapper: body (JSON/form/text), query, params, cookies, headers, `ctx.send`.
16+
- **Middleware** — Global, path-specific. CORS, SecHeaders, Body Limit, Basic Auth, Session, WebSocket.
17+
- **Static files**`router.static(urlPath, options)` with optional etag and cache-control.
18+
- **Error handling** — Pluggable error response builder and error middleware; default HTML/JSON by `Accept`.
19+
- **Frontend optional** — Use any stack (Vite, React, etc.); Deserve stays the server.
820

9-
Add Deserve using the `deno add` command:
21+
## Installation
22+
23+
> [!NOTE]
24+
> **Prerequisites:** [Deno](https://deno.com/) 2.5.4 or later.
1025
1126
```bash
27+
# Add Deserve from JSR
1228
deno add jsr:@neabyte/deserve
1329
```
1430

15-
Follow our [installing guide](https://docs-deserve.neabyte.com/en/getting-started/installation) for more information.
16-
17-
## Table of Contents
18-
19-
- **Getting Started**
20-
- [Installation](https://docs-deserve.neabyte.com/en/getting-started/installation) - Set up Deserve in your project
21-
- [Quick Start](https://docs-deserve.neabyte.com/en/getting-started/quick-start) - Create your first API in minutes
22-
- [Server Configuration](https://docs-deserve.neabyte.com/en/getting-started/server-configuration) - Server setup and shutdown
23-
- [Routes Configuration](https://docs-deserve.neabyte.com/en/getting-started/routes-configuration) - Configure router options
24-
25-
- **Core Concepts**
26-
- [Philosophy](https://docs-deserve.neabyte.com/en/core-concepts/philosophy) - Framework design principles
27-
- [File-based Routing](https://docs-deserve.neabyte.com/en/core-concepts/file-based-routing) - How file structure becomes API endpoints
28-
- [Route Patterns](https://docs-deserve.neabyte.com/en/core-concepts/route-patterns) - Dynamic routes and parameter matching
29-
- [Context Object](https://docs-deserve.neabyte.com/en/core-concepts/context-object) - Request context wrapper with convenient methods
30-
- [Request Handling](https://docs-deserve.neabyte.com/en/core-concepts/request-handling) - Enhanced request object with automatic parsing
31-
32-
- **Middleware**
33-
- [Use Global](https://docs-deserve.neabyte.com/en/middleware/global) - Cross-cutting functionality
34-
- [Use Route-Specific](https://docs-deserve.neabyte.com/en/middleware/route-specific) - Targeted middleware for specific routes
35-
- [Basic Auth](https://docs-deserve.neabyte.com/en/middleware/basic-auth) - HTTP Basic Authentication
36-
- [Body Limit](https://docs-deserve.neabyte.com/en/middleware/body-limit) - Enforce maximum request body size
37-
- [CORS](https://docs-deserve.neabyte.com/en/middleware/cors) - Cross-origin request handling
38-
- [Security Headers](https://docs-deserve.neabyte.com/en/middleware/security-headers) - Set HTTP security headers to protect your application
39-
- [WebSocket](https://docs-deserve.neabyte.com/en/middleware/websocket) - Real-time bidirectional communication
40-
41-
- **Response Utilities**
42-
- [JSON Format](https://docs-deserve.neabyte.com/en/response/json) - Create JSON responses easily
43-
- [Text Format](https://docs-deserve.neabyte.com/en/response/text) - Plain text responses
44-
- [HTML Format](https://docs-deserve.neabyte.com/en/response/html) - HTML content responses
45-
- [File Downloads](https://docs-deserve.neabyte.com/en/response/file) - Download files from filesystem
46-
- [Data Downloads](https://docs-deserve.neabyte.com/en/response/data) - Download in-memory content
47-
- [Redirects](https://docs-deserve.neabyte.com/en/response/redirect) - Redirect responses
48-
- [Custom Responses](https://docs-deserve.neabyte.com/en/response/custom) - Full control over response options
49-
50-
- **Static Files**
51-
- [Basic Static Serving](https://docs-deserve.neabyte.com/en/static-file/basic) - Serve static files from directories
52-
- [Multiple Directories](https://docs-deserve.neabyte.com/en/static-file/multiple) - Serve from multiple locations
53-
54-
- **Error Handling**
55-
- [Default Behavior](https://docs-deserve.neabyte.com/en/error-handling/default-behavior) - Automatic error handling
56-
- [Object Details](https://docs-deserve.neabyte.com/en/error-handling/object-details) - Detailed error information
31+
See the [installation guide](https://docs-deserve.neabyte.com/en/getting-started/installation) for details.
5732

58-
## Contributing
33+
## Quick Start
34+
35+
Create a routes directory and export HTTP method handlers. Start the server.
36+
37+
```typescript
38+
import { Router } from 'jsr:@neabyte/deserve'
39+
40+
// Create router and point to your routes directory
41+
const router = new Router({ routesDir: './routes' })
42+
43+
// Start server on port 8000
44+
await router.serve(8000)
45+
```
46+
47+
**Example route**`routes/hello.ts`:
48+
49+
```typescript
50+
import type { Context } from 'jsr:@neabyte/deserve'
51+
52+
// Export GET (or POST, PUT, etc.) — path comes from file location
53+
export function GET(ctx: Context) {
54+
return ctx.send.json({ message: 'Hello from Deserve' })
55+
}
56+
```
5957

60-
**Help us make Deserve even simpler!** Every contribution helps make building APIs effortless.
58+
- [Quick Start (docs)](https://docs-deserve.neabyte.com/en/getting-started/quick-start)
59+
- [File-Based Routing](https://docs-deserve.neabyte.com/en/core-concepts/file-based-routing)
6160

62-
### How to Contribute
61+
## Build & Test
62+
63+
From the repo root (requires [Deno](https://deno.com/)).
64+
65+
**Check** — format, lint, and typecheck:
66+
67+
```bash
68+
# Format, lint, and typecheck source
69+
deno task check
70+
```
71+
72+
**Test** — run tests (under `tests/`, uses `--allow-read` for fixtures):
73+
74+
```bash
75+
# Run tests in tests/ (uses --allow-read for fixtures)
76+
deno task test
77+
```
78+
79+
**Benchmark** — performance runs with autocannon; see [benchmark/README.md](benchmark/README.md) for how to run and interpret results.
80+
81+
## Documentation
82+
83+
Full docs (EN / ID): **[docs-deserve.neabyte.com](https://docs-deserve.neabyte.com)**
84+
85+
- **Getting Started** — Installation, Quick Start, Server & Routes configuration
86+
- **Core Concepts** — Philosophy, file-based routing, route patterns, Context, request handling
87+
- **Middleware** — Global, route-specific, Basic Auth, Body Limit, CORS, Security Headers, WebSocket
88+
- **Response** — JSON, text, HTML, file/data download, redirect, custom
89+
- **Static Files** — Basic and multiple directories
90+
- **Error Handling** — Default behavior, error object details
91+
92+
## Contributing
6393

64-
- **Report Bugs** - Found something broken? Let us know via [GitHub Issues](https://github.com/NeaByteLab/Deserve/issues)
65-
- **Suggest Features** - Have an idea that aligns with our simplicity-first philosophy? [Create an issue](https://github.com/NeaByteLab/Deserve/issues/new)
66-
- **Fix & Improve** - Submit [Pull Requests](https://github.com/NeaByteLab/Deserve/pulls) for bug fixes, typos, or code improvements
67-
- **Build Middleware** - Create and share third-party middleware that extends Deserve's capabilities
68-
- **Improve Docs** - Help us make the documentation clearer (supports English and Indonesian!)
69-
- **Use Deserve** - The best contribution? Use it in your projects and share your feedback
94+
- **Bugs & ideas**[GitHub Issues](https://github.com/NeaByteLab/Deserve/issues)
95+
- **Code & docs**[Pull Requests](https://github.com/NeaByteLab/Deserve/pulls) welcome; docs support English and Indonesian.
96+
- **Use it** — Try Deserve in your projects and share feedback.
7097

7198
## License
7299

73-
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
100+
This project is licensed under the MIT license. See [LICENSE](LICENSE) for details.

0 commit comments

Comments
 (0)