forked from mirrors/LibreTranslate
wsgi support
This commit is contained in:
parent
29457397a1
commit
64d270dc4d
3 changed files with 47 additions and 9 deletions
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` |
|
| --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` |
|
| --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
|
## 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.
|
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.
|
||||||
|
|
22
app/main.py
22
app/main.py
|
@ -1,4 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import sys
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
from app.app import create_app
|
from app.app import create_app
|
||||||
|
@ -103,17 +104,20 @@ def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
app = create_app(args)
|
app = create_app(args)
|
||||||
|
|
||||||
if args.debug:
|
if sys.argv[0] == '--wsgi':
|
||||||
app.run(host=args.host, port=args.port)
|
return app
|
||||||
else:
|
else:
|
||||||
from waitress import serve
|
if args.debug:
|
||||||
|
app.run(host=args.host, port=args.port)
|
||||||
|
else:
|
||||||
|
from waitress import serve
|
||||||
|
|
||||||
serve(
|
serve(
|
||||||
app,
|
app,
|
||||||
host=args.host,
|
host=args.host,
|
||||||
port=args.port,
|
port=args.port,
|
||||||
url_scheme="https" if args.ssl else "http",
|
url_scheme="https" if args.ssl else "http",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
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 a new issue