Compare commits
2 Commits
v1.3
...
a568abeb49
| Author | SHA1 | Date | |
|---|---|---|---|
|
a568abeb49
|
|||
|
4652af3a2d
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,3 +14,5 @@ plugins/signatures.json
|
|||||||
user_data/
|
user_data/
|
||||||
customPlugins/
|
customPlugins/
|
||||||
cache/
|
cache/
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ requests-doh
|
|||||||
Flask-QRcode
|
Flask-QRcode
|
||||||
PySocks
|
PySocks
|
||||||
python-git-info
|
python-git-info
|
||||||
|
waitress
|
||||||
66
server.py
66
server.py
@@ -1,38 +1,52 @@
|
|||||||
from flask import Flask
|
|
||||||
from main import app
|
|
||||||
import main
|
|
||||||
from gunicorn.app.base import BaseApplication
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import platform
|
||||||
|
from main import app
|
||||||
|
from waitress import serve
|
||||||
|
|
||||||
|
|
||||||
class GunicornApp(BaseApplication):
|
threads = 4
|
||||||
def __init__(self, app, options=None):
|
|
||||||
self.options = options or {}
|
|
||||||
self.application = app
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
def load_config(self):
|
def gunicornServer():
|
||||||
for key, value in self.options.items():
|
from gunicorn.app.base import BaseApplication
|
||||||
if key in self.cfg.settings and value is not None:
|
class GunicornApp(BaseApplication):
|
||||||
self.cfg.set(key.lower(), value)
|
def __init__(self, app, options=None):
|
||||||
|
self.options = options or {}
|
||||||
|
self.application = app
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
def load(self):
|
def load_config(self):
|
||||||
return self.application
|
for key, value in self.options.items():
|
||||||
|
if key in self.cfg.settings and value is not None:
|
||||||
|
self.cfg.set(key.lower(), value)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def load(self):
|
||||||
workers = 1
|
return self.application
|
||||||
threads = 2
|
|
||||||
if workers is None:
|
|
||||||
workers = 1
|
|
||||||
if threads is None:
|
|
||||||
threads = 2
|
|
||||||
workers = int(workers)
|
|
||||||
threads = int(threads)
|
|
||||||
options = {
|
options = {
|
||||||
'bind': '0.0.0.0:5000',
|
'bind': '0.0.0.0:5000',
|
||||||
'workers': workers,
|
'workers': 2,
|
||||||
'threads': threads,
|
'threads': threads,
|
||||||
}
|
}
|
||||||
gunicorn_app = GunicornApp(app, options)
|
gunicorn_app = GunicornApp(app, options)
|
||||||
print('Starting server with ' + str(workers) + ' workers and ' + str(threads) + ' threads', flush=True)
|
print(f'Starting server with Gunicorn on {platform.system()} with {threads} threads...', flush=True)
|
||||||
gunicorn_app.run()
|
gunicorn_app.run()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# Check if --gunicorn is in the command line arguments
|
||||||
|
if "--gunicorn" in sys.argv:
|
||||||
|
gunicornServer()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
print(f'Starting server with Waitress on {platform.system()} with {threads} threads...', flush=True)
|
||||||
|
print(f'Press Ctrl+C to stop the server', flush=True)
|
||||||
|
print(f'Serving on http://0.0.0.0:5000/', flush=True)
|
||||||
|
serve(app, host="0.0.0.0", port=5000, threads=threads)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user