Skip to content

gominima/cors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minima

This is package is wrapper based on rs/cors package made for minima.


Geting Started

Install the package using go get github.com/gominima/cors and call it in your main function


package main

import (
	"github.com/gominima/cors"
	"github.com/gominima/minima"
)

func main() {
	app := minima.New()
	crs := cors.New()
	app.Get("/", func(res *minima.Response, req *minima.Request) {
		res.OK().Send("Hello World")
		res.CloseConn()
	})
	app.Use(crs.AllowAll())
	app.Listen(":3000")
}

Try curling the localhost the result would be something like this


$ curl -D - -H 'Origin: http://abc.com' http://localhost:3000/
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Vary: Origin
Date: Wed, 09 Feb 2022 03:42:42 GMT
Content-Length: 11
Content-Type: text/plain; charset=utf-8

Custom Cors

Using your own custom cors config is as simple as it gets thanks to rs/cors


app := minima.New()
crs := cors.New()
c := crs.NewCors(cors.Options{
    AllowedOrigins: []string{"http://ur_url.com"},
    AllowCredentials: true,
    // Enable Debugging for testing, consider disabling in production
    Debug: true,
})
app.Use(c())

About

⚡Simple cors middleware package for minima

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages