Skip to content

Commit 39ca3c4

Browse files
committed
Replace negotiator with @hapi/accept
1 parent c539385 commit 39ca3c4

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

package-lock.json

Lines changed: 10 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@
9393
"typescript": "^3.7.4"
9494
},
9595
"dependencies": {
96+
"@hapi/accept": "^5.0.1",
9697
"@types/escape-html": "^1.0.0",
97-
"@types/negotiator": "^0.6.1",
98-
"escape-html": "^1.0.3",
99-
"negotiator": "^0.6.2"
98+
"escape-html": "^1.0.3"
10099
}
101100
}

src/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Negotiator from "negotiator";
1+
import { mediaType } from "@hapi/accept";
22
import escapeHTML from "escape-html";
33

44
/**
@@ -90,13 +90,10 @@ function renderJSON(req: Request, output: Output) {
9090
* Render HTTP response.
9191
*/
9292
function render(req: Request, output: Output) {
93-
const negotiator = new Negotiator({
94-
headers: {
95-
accept: req.headers.get("accept") || undefined,
96-
},
97-
});
98-
99-
const type = negotiator.mediaType(["text/html", "application/json"]);
93+
const type = mediaType(req.headers.get("accept") || "", [
94+
"text/html",
95+
"application/json",
96+
]);
10097
if (type === "text/html") return renderHTML(req, output);
10198
return renderJSON(req, output);
10299
}

0 commit comments

Comments
 (0)