gothinkster / flask-realworld-example-app

Exemplary real world JSON API built with Flask (Python)
https://realworld.io/
MIT License
897 stars 308 forks source link

cross-domain problem? #2

Closed jk7g14 closed 7 years ago

jk7g14 commented 7 years ago

I started flask in port 5000

and started elm realworld in 8000

it seems to work but when I tried to sign up, it didn't work :(

I checked the dev.db and data was added but can't login.

and in flask server

I saw

127.0.0.1 - - [05/Jul/2017 18:07:14] "OPTIONS /api/users HTTP/1.1" 200 - 127.0.0.1 - - [05/Jul/2017 18:07:15] "POST /api/users HTTP/1.1" 422 - 127.0.0.1 - - [05/Jul/2017 18:07:20] "OPTIONS /api/users HTTP/1.1" 200 - 127.0.0.1 - - [05/Jul/2017 18:07:20] "POST /api/users HTTP/1.1" 422 -

do you know how it can be solved ?

realazizk commented 7 years ago

@jk7g14 sure, this seems to be an issue here https://github.com/rtfeldman/elm-spa-example/blob/74cb1e5da06492050ed4cf3002c3eef2d2ca184d/src/Data/User.elm#L29 the model excepts createdAt and updatedAt though it's specified in the API spec https://github.com/gothinkster/realworld/tree/master/api#users-for-authentication I also think that the other frontends don't require this.

realazizk commented 7 years ago

anyways 00abe1d1cae049b542326ab9c55427e6fe069351 fixes it, could you please test this further, it seems that the elm frontend don't adhere to the API spec.

jk7g14 commented 7 years ago

I can login and register! It's working fine now! I think you're right. There is no createdAt and updatedAt in API spec. Then it's Elm's fault ! right?

I removed createdAt and updatedAt in Elm and it also worked without correction in your code!!
I think it was not flask's fault. Thank you man. Awesome!

By the way, you know how I can just allow specific address to access flask like this? https://github.com/gothinkster/django-realworld-example-app/blob/master/conduit/settings.py#L132

realazizk commented 7 years ago

@jk7g14 I don't think it's anyone's fault, it's just not specified in the API spec, as for the origin whitelist this should do it d170b00ed80889fddd66ad9aad2a723d33d6660b you can specify the whitelist in the config now, and you can have a different whitelist environment for every scenario (in dev, test or production).

Thanks.