Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
fix(routes): accept header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Nov 1, 2022
1 parent d2ad55d commit e5fbb4b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/routes/admin/healthcheck/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const cors = require("@fastify/cors");

const { healthcheckGetSchema } = require("./schema");

const accepts = ["text/plain"];

/**
* @author Frazer Smith
* @description Sets routing options for server for healthcheck endpoint.
Expand All @@ -28,7 +30,7 @@ async function route(server, options) {
onRequest: async (req) => {
if (
// Catch unsupported Accept header media types
!req.accepts().type(healthcheckGetSchema.produces)
!req.accepts().type(accepts)
) {
throw server.httpErrors.notAcceptable();
}
Expand Down
4 changes: 3 additions & 1 deletion src/routes/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const staticPlugin = require("@fastify/static");

const { docsGetSchema } = require("./schema");

const accepts = ["text/html"];

/**
* @author Frazer Smith
* @description Sets routing options for server.
Expand Down Expand Up @@ -39,7 +41,7 @@ async function route(server) {
onRequest: async (req) => {
if (
// Catch unsupported Accept header media types
!req.accepts().type(docsGetSchema.produces)
!req.accepts().type(accepts)
) {
throw server.httpErrors.notAcceptable();
}
Expand Down
4 changes: 3 additions & 1 deletion src/routes/docs/openapi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const cors = require("@fastify/cors");

const { docsOpenapiGetSchema } = require("./schema");

const accepts = docsOpenapiGetSchema.produces;

/**
* @author Frazer Smith
* @description Sets routing options for server.
Expand All @@ -26,7 +28,7 @@ async function route(server, options) {
onRequest: async (req) => {
if (
// Catch unsupported Accept header media types
!req.accepts().type(docsOpenapiGetSchema.produces)
!req.accepts().type(accepts)
) {
throw server.httpErrors.notAcceptable();
}
Expand Down

0 comments on commit e5fbb4b

Please sign in to comment.