RPC text/javascript result Content-Type question #3387
-
Hi, I would like to return a js module code from my RPC function:
The module is loaded from html:
It looks like PostgREST (12.0.2) response has content type header set to "application/json" (and not "text/javascript"). Accept header sent by the browser is I tried to find a solution and there is a discussion about setting "pgrst.accept" on the function - is this necessary? And if that's so - what should be its value? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
No, that was only an idea, but not implemented like that. Instead we now have the I just looked into one of the functions where I use this, and it seems I am still doing this: SELECT set_config('response.headers', '[{"Content-Type": "text/css"}]', true); Even though the function |
Beta Was this translation helpful? Give feedback.
-
If the browser sends This is a limitation of the design of custom media type handlers. There are more flexible alternatives (like #3037), which could come in the future. For now you'll have to use the any handler workaround. |
Beta Was this translation helpful? Give feedback.
If the browser sends
*/*
, you need to use the any handler. Otherwise postgREST will use the defaultapplication/json
handler (which doesjson_agg
underlyingly). You'll manually have to set the"text/javascript"
withset_config('response.headers'
.This is a limitation of the design of custom media type handlers. There are more flexible alternatives (like #3037), which could come in the future. For now you'll have to use the any handler workaround.