fnproject/fdk-go

Handling CORS headers inside a function

Closed this issue · 4 comments

Hi there,

I'm trying to use fn and Golang to build an API that is callable from a browser. Within my function, I'd like to be able to handle CORS headers on the HTTP response, but I'm finding that fdk.setHeader() is prepending text to my header name, but it doesn't do it for the Content-Type examples provided.

So if I do this in my function:

	fdk.SetHeader(out, "Access-Control-Allow-Origin", "*")
	fdk.SetHeader(out, "Content-Type", "application/json")

I see this if you hit the function with curl -v

< Content-Type: application/json
< Fn-Http-H-Access-Control-Allow-Origin: *

So, I can set Content-Type directly but not add CORS headers to the response so that the browser will handle it correctly.

Any guidance?

Hi! There's a lot of work being done for Go FDK here: #39.
I recommend you to try that PR and see if that works for you.

Hi Denis, thanks for the pointer and I'm sorry for missing that. That's definitely the right conversation and it looks like you're close to solving the larger set of issues. I'll move onto Java while you're working on it in parallel. Feel free to close this one if you want and I'll track the other.

@nerdguru with #39 closed via merged commit 26ed643 into master on Oct 25' this should unblock fonk-apps/fonk-examples#6

this may be closed then? feel free to re-open if that is not the case. when using http triggers the headers should be returned from the function and from the trigger endpoint as expected (without a prefix).