Skip to content

Conversation

@RomainLanz
Copy link
Member

Hey there! 👋🏻

This PR allows us to use a function instead of hardcoding a string for the forceContentNegotiationTo options.
It can be helpful when you have an application doing SSR & having some API routes that need to be forced to JSON.

Something similar is already done inside the shield module.

exceptRoutes: ({ request }) => request.url().includes('/api'),

@targos
Copy link
Member

targos commented Dec 6, 2021

Should we await the result of the function (I don't know if it makes sense for this one to be implemented as async)?

@RomainLanz
Copy link
Member Author

It could make sense, but I believe we should not handle it.

Having an async function means there is some side-effect. If someone has this use-case, he would be better of creating a middleware instead of coding it inside the configuration.

@thetutlage
Copy link
Member

Yeah, async within config is something I will avoid too. Should we close this PR then?

@RomainLanz
Copy link
Member Author

This PR does not add the support for asyncconfiguration, so we are all good to go.

@thetutlage thetutlage merged commit 73f4c6f into develop Dec 6, 2021
@RomainLanz RomainLanz deleted the feat/improve-http-config branch December 6, 2021 14:02
@carlmathisen
Copy link

carlmathisen commented Dec 19, 2021

Thank you guys - this is such a good addition! My main use case was the app being an API, with a few extra endpoints for an admin panel. To be able to flexibly configure forced JSON on /v1/api endpoints, similar to @RomainLanz's example was exactly what I needed, and I'm sure it will be useful for others too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants