drashland / deno-drash-realworld-example-app

Deno + Drash RealWorld example app
MIT License
59 stars 292 forks source link

CORs Issue for Apache #46

Open ebebbington opened 4 years ago

ebebbington commented 4 years ago

When using localhost:8080, we get the below errors when sending a POST to /login and /register

@Guergeiro Also mentioned we get CORs problems when using 127.0.0.1:*

Figure out a solution to this to fix the errors.

Errors (in console)

Access to XMLHttpRequest at 'http://localhost:1667/users' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

actions.js:118 Registration unsuccessful.

xhr.js:175 POST http://localhost:1667/users net::ERR_FAILED
    dispatchXhrRequest @ xhr.js:175
    xhrAdapter @ xhr.js:18
    dispatchRequest @ dispatchRequest.js:40
    Promise.then (async)
    request @ Axios.js:64
    Axios.<computed> @ Axios.js:88
    wrap @ bind.js:11
    eval @ actions.js:108
    register @ actions.js:107
    wrappedActionHandler @ vuex.esm.js:840
    dispatch @ vuex.esm.js:478
    boundDispatch @ vuex.esm.js:361
    eval @ Register.vue?./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue- 
    loader-options:73
    Promise.then (async)
    onSubmit @ Register.vue?./node_modules/babel-loader/lib!./node_modules/vue-loader/lib?? 
    vue-loader-options:72
    submit @ Register.vue?./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader- 
    options!./node_modules/vue-loader/lib??vue-loader-options:44
    invokeWithErrorHandling @ vue.js:1888
    invoker @ vue.js:2219
    original._wrapper @ vue.js:7510

actions.js:119 Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
    at eval (actions.js:119)
crookse commented 4 years ago

Might have to implement the OPTIONS method. I wonder if axios does a preflight check before it does the actual POST.

Guergeiro commented 4 years ago

I believe, this is something that we need to handle in Drash itself... If we add a simple middleware that accepts any origin, should work, right?

crookse commented 4 years ago

That's a good point. Didn't think about that. Could work.

ebebbington commented 4 years ago

@Guergeiro feel free to take this issue on 😆