go echo: CORS-support

At the moment I'm playing around with golang and echo for creating a rest-service. Since my frontend is going to be flutter which is able to build out of the box to android,iOS and Web.

But testing an http-connection from the generated javascript to the echo-server ends up in an 'xmlhttprequest error'. That seems to be releated with 'Cross-Origin Resource Sharing'. We need to allow all requests by setting in the header somthing like this:

'Access-Control-Allow-Origin': "*"

To achieve this in echo you can do this via a middleware:

	
    import (
	...
	"github.com/labstack/echo/middleware"
    )
    
    ...
    e.Use(middleware.CORS())
    

Here a short youtube-video explaining the problem a bit:

The reason behind the silly CORS error! Why do you get it? Animated Explained
#cors #webdev #comscience Hello everyone and welcome to comscience simplified. In this week’s video we look into one of the major causes for irritation among...