heroku-python / flask-sockets

[DEPRECATED] Alternative: https://github.com/miguelgrinberg/flask-sock
MIT License
1.74k stars 164 forks source link

Use werkzeug URL routing (like Flask does) / get rid of middleware. #7

Closed mbr closed 10 years ago

mbr commented 10 years ago

...ers.

This allows the use of parameters in URLs, for example a route of

@sockets.route("/chat/<name>/")
def chat_channel(name):
   # ...

properly gets passed the channel name.

mbr commented 10 years ago

The first commit is a mild improvement, the second a bit more drastic. I'd love some feedback on this, I think both are a cleaner approach in the long run that what is done currently.

I'm okay with putting this in another library as well though.

These were supposed to be two pull requests, but github grouped them unfortunately. Oh well....

mbr commented 10 years ago

Added the @socket wrapper. Github keeps merging all my pull requests, so I'll have to deal with that for now I guess.

d0ugal commented 10 years ago

GitHub will "merge" the pull requests if you update the source of the pull request (essentially your merging them in your master branch and GitHub is just using that).

Do each PR from a different branch if you don't want them to be lumped together.

versae commented 10 years ago

I was implementing the same exact thing as @mbr did in the first PR. I'll try the second approach using the LocalProxy from Werkzeug and see how it goes.

kennethreitz commented 10 years ago

Very nice! This is a pretty massive breaking change, though. I'll need to think about it. I definitely prefer the old api as well. Maybe there's a way to allow both ways to be used.

JakeAustwick commented 10 years ago

Any update on this? The way the routes are currently done means that url_for() doesn't work.

mbildner commented 10 years ago

as it stands now is there some other way to do variable routing?

rgrinberg commented 10 years ago

I'd like to have this as well. It's definitely a unintuitive that path parameters don't work.

arbyter commented 10 years ago

Great improvement! Please accept the pull request.

fobdy commented 10 years ago

+1

amarder commented 10 years ago
  1. flask_sockets is awesome!
  2. being able to set up multiple chat rooms with @sockets.route would be very nice.

I am going to play around with mbr's code and see if it works for me.

In my search of github, I also found this code which uses flask.Blueprint and socketio (I'm not sure if it works):

https://github.com/002Aface/mmotd-server-socket/blob/1480899dbb539e77aa3a3fffceda7f6f4791de4b/app/views/sockets.py

codebynumbers commented 10 years ago

+1 here too, looking for "flask" variables in url routes as well

Edit: PR #18 works practically right out of the box without need to mess with LocalProxy, + no breaking changes.

kennethreitz commented 10 years ago

Going to go with #18 :)