mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-12-24 10:06:43 +02:00
wsgi support
This commit is contained in:
parent
29457397a1
commit
64d270dc4d
15
README.md
15
README.md
@ -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.
|
||||
|
@ -1,4 +1,5 @@
|
||||
import argparse
|
||||
import sys
|
||||
import operator
|
||||
|
||||
from app.app import create_app
|
||||
@ -103,6 +104,9 @@ def main():
|
||||
args = parser.parse_args()
|
||||
app = create_app(args)
|
||||
|
||||
if sys.argv[0] == '--wsgi':
|
||||
return app
|
||||
else:
|
||||
if args.debug:
|
||||
app.run(host=args.host, port=args.port)
|
||||
else:
|
||||
|
19
wsgi.py
Normal file
19
wsgi.py
Normal file
@ -0,0 +1,19 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user