-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force h3 to send the correct content-type for JSON (#324)
- Loading branch information
Showing
3 changed files
with
15 additions
and
5 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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
'use strict' | ||
|
||
const { createServer } = require('node:http') | ||
const { createApp, toNodeListener, eventHandler } = require('h3') | ||
const { createApp, toNodeListener, eventHandler, setHeader } = require('h3') | ||
|
||
const app = createApp() | ||
app.use('/', eventHandler(() => ({ hello: 'world' }))) | ||
app.use('/', eventHandler((ev) => { | ||
// Unfortunatly, we need to set the content-type manually | ||
// to level the paying field | ||
setHeader(ev, 'content-type', 'application/json; charset=utf-8') | ||
return { hello: 'world' } | ||
})) | ||
|
||
createServer(toNodeListener(app)).listen(process.env.PORT || 3000) |
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