forked from elysiajs/elysia-html
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use status code specified in context
Fix elysiajs#56 Previously the html plugin would always return 200 for HTML responses. This commit adds support for reading the status code in set.status to determine which status code to use. It fallbacks to 200 if no status code is set. It uses the StatusMap exported by Elysia to map res.status values supplied as string literals. Example for statuscode has been added to examples folder showcasing returning Forbidden status. Added test for overriding status code. Needed to upgrade Elysia peer and dev dependency to a newer version as the StatusMap value was not available in elysia 1.0.2. Running bun install and pnpm install also updated the patch versions of @kitajs/* dependencies.
- Loading branch information
Showing
8 changed files
with
133 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Elysia } from 'elysia' | ||
import { html } from '../src' | ||
|
||
const app = new Elysia() | ||
.use(html({ autoDetect: true })) | ||
.get('/a', ({ html, set }) => { | ||
set.status = 'Forbidden' | ||
return html(`<h1>Forbidden!</h1>`) | ||
}) | ||
.compile() | ||
|
||
console.log(app.routes[0]?.composed?.toString()) | ||
|
||
app.handle(new Request('http://localhost:8080/a')) | ||
.then((x) => x.status) | ||
.then(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters