Skip to content
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

CORS configuration #56

Open
wkulczi opened this issue Jun 4, 2021 · 5 comments
Open

CORS configuration #56

wkulczi opened this issue Jun 4, 2021 · 5 comments

Comments

@wkulczi
Copy link

wkulczi commented Jun 4, 2021

First off, thanks for creating raspilive, it saved me a lot of time setting similar solution.
I have a bit of a problem with connecting served file with web app I've created because of a CORS error. I guess I need to set Access-Control-Allow-Origin to my website address. Can you point me to the direction where should I change the server configuration to edit its CORS headers?
I have zero GOlang experience but I'm willing to learn anything

Thanks a lot.

@jaredpetersen
Copy link
Owner

Yeah, so it looks like you'd need to add some middleware here to set up your CORs stuff. This should probably be handled by the application out of the box. But in the mean time, I think you need

A new function here:

func corsMiddleware(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		// TODO see https://github.com/GoogleCloudPlatform/golang-samples/blob/master/functions/http/cors.go#L29-L39
		next.ServeHTTP(w, r)
	})
}

And then add it to the middlware chain here

middlewareChain = middlewareChain.Append(corsMiddleware)

There's also this library which appears to be a little more turn-key but I haven't used it before.

I'll leave this open to remind myself to look more into providing better support for this in the future.

@wkulczi
Copy link
Author

wkulczi commented Jun 10, 2021

Can confirm that this solution works, thanks again.

@matthiasbaldi
Copy link

@jaredpetersen When do you think you will implement it in the raspilive?

@jaredpetersen
Copy link
Owner

Eventually 🤷‍♂️

I've been taking a small break from open source to catch up on other hobbies. Is there an urgent need?

@matthiasbaldi
Copy link

Oh sure, no I think it is also solvable with a reverse proxy in front of the stream.
So it is not urgent ;) take your time. Sadly I can not help with it because it is now written in GO,
I do not have enough knowledge about that ^^

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

No branches or pull requests

3 participants