2 Commits

Author SHA1 Message Date
a568abeb49 fix: Don't import gunicorn unless specified by args
All checks were successful
Build Docker / Build Image (push) Successful in 45s
2025-02-05 13:51:01 +11:00
4652af3a2d feat: Add new server backend to add windows support
All checks were successful
Build Docker / Build Image (push) Successful in 1m18s
2025-02-05 13:20:09 +11:00
3 changed files with 45 additions and 28 deletions

2
.gitignore vendored
View File

@@ -14,3 +14,5 @@ plugins/signatures.json
user_data/ user_data/
customPlugins/ customPlugins/
cache/ cache/
build/
dist/

View File

@@ -9,3 +9,4 @@ requests-doh
Flask-QRcode Flask-QRcode
PySocks PySocks
python-git-info python-git-info
waitress

View File

@@ -1,11 +1,15 @@
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 gunicornServer():
from gunicorn.app.base import BaseApplication
class GunicornApp(BaseApplication):
def __init__(self, app, options=None): def __init__(self, app, options=None):
self.options = options or {} self.options = options or {}
self.application = app self.application = app
@@ -18,21 +22,31 @@ class GunicornApp(BaseApplication):
def load(self): def load(self):
return self.application return self.application
if __name__ == '__main__':
workers = 1
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)