-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't convert to JSON when calling a function which returns text and sets Content-Type as non-json #2138
Labels
Comments
You might want to look into the You should be able to set it to This is even covered in a test-case: postgrest/test/spec/Feature/HtmlRawOutputSpec.hs Lines 14 to 30 in c7cadcd
|
@wolfgangwalther This is perfect! Thank you. |
nileshtrivedi
added a commit
to nileshtrivedi/postgrest-docs
that referenced
this issue
Jan 25, 2022
[I ran into a gotcha](PostgREST/postgrest#2138). Improving docs so that others can avoid this. My first PR in this project, and I haven't tested the generated docs. Feel free to discard if it's not appropriate or not done correctly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Environment
Description of issue
I wanted to serve the base HTML page directly from postgrest. So, I created a postgresql function that returns text and sets
Content-Type
header totext/html
like this:And then I expected, the HTML to be returned at
/rpc/homepage
:As you can see, the function's returned value was string which was converted to JSON and hence it includes double-quotes. This was not expected, as I head set the content-type to be
text/html
instead ofapplication/json
.Another unexpected behavior was the trailing
%
in the response body.Possibly related issues:
pgrst.accept
setting to RPC #1582What am I trying to achieve and what are my constraints:
I'm trying to ship an on-premise webapp with SQL+JS stack. Essentially, we will give users an SQL script to run which defines the models and functions, postgREST would both provide CRUD apis as well as serve the base HTML page. The page would then load JS/CSS files from CDN which are published and maintained by developers.
Workaround
@laurenceisla suggested in Gitter chat that I inject an
Accept: text/plain
header using nginx rewrite rules like this:And then
http://localhost/html/homepage
should return the HTML ready for browser's consumption.But IMHO, it still seems wrong for postgrest to force a conversion to JSON when the function explicitly sets a content-type as non-JSON.
The text was updated successfully, but these errors were encountered: