Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A livereload server for wsgi #47

Closed
lepture opened this issue Dec 9, 2013 · 6 comments
Closed

A livereload server for wsgi #47

lepture opened this issue Dec 9, 2013 · 6 comments
Labels
type: feature A self-contained enhancement or new feature

Comments

@lepture
Copy link
Owner

lepture commented Dec 9, 2013

Now, livereload will be a library rather than an application. in version: 2.0.0

from livereload import Server

server = Server(wsgi_app)
# run a shell command
server.watch('static/*.stylus', 'make static')
# run a function
server.watch('foo.txt', lambda: print('foo'))
server.serve()

With this snippet it will serve an wsgi application, and it will insert the livereload.js script into the response body.

@lepture
Copy link
Owner Author

lepture commented Dec 12, 2013

@miracle2k any suggestions?

@miracle2k
Copy link
Contributor

A significant challenge for me was integrating the tornado livereload server that currently exists with werkzeug's "runserver". Two thoughts:

  1. Because both want to run a main loop, I have to put one in a thread.

  2. werkzeug's runserver has a bunch of nice functionality, most significantly auto-reload on source change - which was an additional challenge because it starts a new process thus leading to a second attempt to run the live reload server.

The new approach would solve (1) nicely.

For (2), the API I would imagine to API to look something like this:

 wsgi_app = livereload(my_wsgiapp)
 werkzeug.runserver(wsgi_app)

But this presumably cannot be done without getting rid of tornado and thus a huge rewrite.

So I would be happy if instead of letting livereload serve I could still optionally do:

 server = Server()
 server.watch()
 Thread(run=server.serve).start()
 werkzeug.runserver(my_wsgiapp)

@lepture
Copy link
Owner Author

lepture commented Dec 13, 2013

@miracle2k you will not need werkzeug's runserver. This server will auto reload on source change too.

@blueyed
Copy link
Contributor

blueyed commented Dec 15, 2013

Works good for me, and can easily replace Django's runserver by using this as wsgi_app:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.local")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

The change from current master would be to not have a global Task object, but add them to the server directly?
Makes sense.

@lepture
Copy link
Owner Author

lepture commented Dec 17, 2013

The latest code is no wsgi branch.

@lepture
Copy link
Owner Author

lepture commented Dec 30, 2013

released.

@lepture lepture closed this as completed Dec 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A self-contained enhancement or new feature
Projects
None yet
Development

No branches or pull requests

3 participants