Comments (7)
In a recent project, I'd needed needed both Auto Reload and Static file serving capabilities.
Using hug, this is the solution I came up with.
- Use
static
for a WSGI compatible static file handling. - Write the API as usual using
hug
. - Use
pecan_mount
to mount__hug__
andstatic
to a single WSGI point. - Run this with
gunicorn
's Auto Reload turned on.
And there, a quick and easy solution. 😆
Here's a snippet in case anybody's interested.
import hug
import pecan_mount
import static
@hug.get('/', versions=1)
def get_root():
return True
# Mount Hug at `/api` and static files at '/'
pecan_mount.tree.graft(__hug_wsgi__, '/api')
pecan_mount.tree.graft(static.Cling("/path/to/static/root"), '/')
app = pecan_mount.tree
Running with gunicorn
: $ gunicorn module:app --reload
I'm looking forward to version 3, though!
from hug.
Closing this as this feature is now completed in development and ready for the next release.
Thanks!
~Timothy
from hug.
Here's a recent discussion about auto-reloading on the django-developers mailing list: https://groups.google.com/forum/#!topic/django-developers/voXNIDdDcpU. It has a few good ideas on how to improve Django's auto-reloading, but it might be useful for Hug too
from hug.
@arthurk, I think that's super helpful as we think about how to implement hug's solution. Thanks for finding and sharing!
~Timothy
from hug.
There is a WIP PR for a debug server in falcon: falconry/falcon#517
from hug.
@sloria thanks for linking! Hopefully will be able to get this in for the 2.0.0 release :)
from hug.
FWIW, here's a link to the relevant code in the latest release of bottle:
https://github.com/bottlepy/bottle/blob/0.12.9/bottle.py#L3131-L3169
https://github.com/bottlepy/bottle/blob/0.12.9/bottle.py#L3109-L3115
from hug.
Related Issues (20)
- TypeError: __call__() missing 1 required positional argument: 'context'
- Splitting APIs over multiple files
- zsh: command not found: hug HOT 1
- How to configure a service?
- Bug: dashed versions of valid command line arguments fail silently
- Add exception in not_found router
- Missing explicit python 3.8 compatibility from release note.
- GET endpoints not working when using prefixes in @hug.object.urls
- Tag the source
- Remove pinning
- pytest-runner not required HOT 1
- distutils has been deprecated in Python 3.10 HOT 1
- Is this project abandoned? HOT 8
- Unexpected conversion during a requests.post() operation
- TypeError: gather() got an unexpected keyword argument 'loop' HOT 2
- CORS Middleware help
- Exception handler: Why find a potential handler doesn't exit the loop
- Implementation bugs for exception catching!
- FYI: cgi module is deprecated in Python 3.11, will be removed in 3.13
- Could you please clarify this deprecation warning?! HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hug.