Last active
August 5, 2022 14:37
-
-
Save lwzm/c7200fd8963f00ad3f3a6ff8058e98a9 to your computer and use it in GitHub Desktop.
gunicorn and pyinstaller and file-upload-app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import shutil | |
from flask import Flask, Response, request | |
app = Flask(__name__) | |
@app.route('/<path:path>', methods=['GET', 'POST']) | |
def hello(path): | |
if request.method == "POST": | |
shutil.copyfileobj(request.stream, open(path, 'wb'), 4096) | |
return '', 201 | |
else: | |
return Response(open(path, 'rb'), mimetype="application/octet-stream") | |
application = app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pyinstaller -y \ | |
--hidden-import gunicorn.glogging \ | |
--hidden-import gunicorn.workers.sync \ | |
--hidden-import app \ | |
file-server-app.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream f { | |
server 127.0.0.4:3000; | |
keepalive 16; | |
} | |
server { | |
server_name f.*; | |
listen 443 ssl http2; | |
root /home/files; | |
location / { | |
proxy_buffering off; | |
proxy_request_buffering off; | |
if ($request_method = POST) { | |
proxy_pass http://f; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from gunicorn.app.base import BaseApplication | |
class Application(BaseApplication): | |
def load_config(self): | |
s = self.cfg.set | |
s('bind', "0.0.0.0:8000") | |
s('workers', 3) | |
s('keepalive', 60) | |
s('timeout', 600) | |
s('accesslog', "-") | |
s('access_log_format', '%(t)s %(h)s "%(r)s" %(s)s %(b)s %(D)s "%(a)s"') | |
def load(self): | |
from app import application | |
return application | |
if __name__ == '__main__': | |
Application().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added these two imports to the beginning of the server.py:
Then, renamed my flask file to __init__.py and placed it into a folder named app. So, now I have a server.py and a folder named app, which contains a __init__.py that hosts my web server logic.
It worked then.
Hope it helps you.