Giter Club home page Giter Club logo

cors's People

Contributors

anatoliid avatar christophercurrie avatar codegangsta avatar hariharan-uno avatar jakejscott avatar maxhawkins avatar rakyll avatar tomsteele avatar umcodemonkey avatar vastbinderj avatar zachlatta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cors's Issues

Set error code 200 for OPTIONS requests

OPTIONS requests ask for a set of headers to be sent with a 200 OK code. This error code is not set by the middleware, so routing continue through the other middlewares and handlers, resulting in incorrect behavior.

For instance, if doing a Basic Auth check right after the CORS check, an OPTIONS request will get 401 Unauthorized error code thus won't perform the call.

My solution is currently to add a catch-all for OPTIONS (see snipet below) with an empty handler, which will result in the correct error code being sent back (instead of 401, 404, etc).


m := martini.New()

m.Use(cors.Allow(&cors.Options{
    AllowAllOrigins: true,
    AllowMethods: []string{"GET"},
}))

r := martini.NewRouter()
r.Options("/**", func() { return })

// Other handlers

m.Action(r.Handle)

http.ListenAndServe(":"+strconv.Itoa(c.Port), m)

Access-Control-Allow-Origin not being passed back to client

Why is the CORS middleware not working for me? I am absolutely stumped.

I'm trying to connect an Angular up up to my REST API. I've written this much smaller app which should just return POST

func App() *martini.ClassicMartini {
    m := martini.Classic()
    m.Use(render.Renderer())

    options := &cors.Options{
        AllowAllOrigins: true,
        AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"},
    }
    m.Use(cors.Allow(options))

    m.Group("/visitor", func(r martini.Router) {
        r.Get("/:id", Get)
        r.Get("", All)
        r.Post("/:id", Post)
        r.Put("/:id", Put)
        r.Options("/**", func() { return })
    })

    return m
}

func Post(params martini.Params) string {
    fmt.Println(params)
    return "POST"
}

func main() {
    m := App()
    listen := fmt.Sprintf("%s:%d", "localhost", 3000)
    fmt.Printf("Simple listening on %s\n", listen)
    log.Fatal(http.ListenAndServe(listen, m))
}

image
image

Using cors.Allow procedurally instead of in the middleware stack

The examples provided demonstrate using cors.Allow() in the Martini middleware stack.

In my case I am working on a router service which has a single handler as middleware and passes off the various actions in a procedural manner.

Is it valid to do the following inside my handler:

doCors := cors.Allow(&cors.Options{
    AllowOrigins:     permittedDomains,
})

doCors(response, request)

I've left out any additional logic.

Many thanks,
Ian

build status 'fail'

The wercker status has been showing the 'fail' state for quite some time now. I guess it was because of some machine error than an actual test failure. @rakyll can you rebuild it so that it won't deter any new visitors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.