Skip to content

Commit 4262085

Browse files
authored
Merge pull request #1 from bogeychan/main
fix: ignored context headers
2 parents 6cf5341 + 037a624 commit 4262085

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

bun.lockb

5.73 KB
Binary file not shown.

example/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const page = `<!DOCTYPE HTML>
1313
</html>`
1414

1515
const app = new Elysia()
16-
.use(html)
16+
.use(html())
1717
.get('/', () => page)
1818
.get('/html', ({ html }) => html(page))
1919
.listen(8080)

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
"release": "npm run build && npm run test && npm publish --access public"
3434
},
3535
"peerDependencies": {
36-
"elysia": ">= 0.1.0-rc.5"
36+
"elysia": ">= 0.4.10"
3737
},
3838
"devDependencies": {
3939
"@types/node": "^18.11.7",
40-
"bun-types": "^0.2.2",
40+
"bun-types": "^0.5.8",
4141
"eslint": "^8.26.0",
42-
"elysia": "^0.3.0-rc.1",
42+
"elysia": "^0.4.10",
4343
"rimraf": "^3.0.2",
4444
"typescript": "^4.8.4"
4545
}

src/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@ import { Elysia } from 'elysia'
22

33
export const html = () => (app: Elysia) =>
44
app
5-
.decorate(
6-
'html',
7-
(value: string) =>
8-
new Response(value, {
5+
.derive((context) => ({
6+
html(value: string) {
7+
8+
//! error: expect(received).toBe(expected)
9+
//! Expected: "text/html"
10+
//! Received: "text/html, text/html"
11+
12+
// context.set.headers['content-type'] = 'text/html';
13+
// return new Response(value, { headers: context.set.headers });
14+
15+
return new Response(value, {
916
headers: {
17+
...context.set.headers,
1018
'content-type': 'text/html'
1119
}
1220
})
13-
)
21+
}
22+
}))
1423
.onAfterHandle((context, response) => {
1524
if (
1625
typeof response === 'string' &&

0 commit comments

Comments
 (0)