Skip to content
Snippets Groups Projects
Commit 64d270dc authored by Piero Toffanin's avatar Piero Toffanin
Browse files

wsgi support

parent 29457397
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,21 @@ docker-compose up -d --build
| --require-api-key-origin | Require use of an API key for programmatic access to the API, unless the request origin matches this domain | `No restrictions on domain origin` |
| --load-only | Set available languages | `all from argostranslate` |
## Run with Gunicorn
```
pip install gunicorn
gunicorn --bind 0.0.0.0:5000 'wsgi:app'
```
You can pass application arguments directly to Gunicorn via:
```
gunicorn --bind 0.0.0.0:5000 'wsgi:app(api_keys=True)'
```
## Manage API Keys
LibreTranslate supports per-user limit quotas, e.g. you can issue API keys to users so that they can enjoy higher requests limits per minute (if you also set `--req-limit`). By default all users are rate-limited based on `--req-limit`, but passing an optional `api_key` parameter to the REST endpoints allows a user to enjoy higher request limits.
......
import argparse
import sys
import operator
from app.app import create_app
......@@ -103,17 +104,20 @@ def main():
args = parser.parse_args()
app = create_app(args)
if args.debug:
app.run(host=args.host, port=args.port)
if sys.argv[0] == '--wsgi':
return app
else:
from waitress import serve
if args.debug:
app.run(host=args.host, port=args.port)
else:
from waitress import serve
serve(
app,
host=args.host,
port=args.port,
url_scheme="https" if args.ssl else "http",
)
serve(
app,
host=args.host,
port=args.port,
url_scheme="https" if args.ssl else "http",
)
if __name__ == "__main__":
......
wsgi.py 0 → 100644
from app import main
def app(*args, **kwargs):
import sys
sys.argv = ['--wsgi']
for k in kwargs:
ck = k.replace("_", "-")
if isinstance(kwargs[k], bool) and kwargs[k]:
sys.argv.append("--" + ck)
else:
sys.argv.append("--" + ck)
sys.argv.append(kwargs[k])
instance = main()
if len(kwargs) == 0:
return instance(*args, **kwargs)
else:
return instance
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment