WSGI compatible (allow gunicorn use)
This commit is contained in:
parent
c59f8f7edb
commit
4e89dde75f
3 changed files with 28 additions and 19 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
||||||
data
|
*.pyc
|
||||||
|
|
||||||
|
data
|
||||||
|
|
|
||||||
20
server.py
20
server.py
|
|
@ -1,4 +1,3 @@
|
||||||
from argparse import ArgumentParser
|
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import urllib.error
|
import urllib.error
|
||||||
|
|
@ -7,18 +6,7 @@ import urllib.request
|
||||||
from flask import Flask, send_file
|
from flask import Flask, send_file
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def create_app(debug_mode: bool = False):
|
||||||
parser = ArgumentParser()
|
|
||||||
parser.add_argument('--host', default='0.0.0.0', help='Server host (default: 0.0.0.0)')
|
|
||||||
parser.add_argument('--port', type=int, default=8000, help='Server port (default: 8000)')
|
|
||||||
parser.add_argument('--debug', action='store_true', help='Run in debug mode (auto-reload on change)')
|
|
||||||
arguments = parser.parse_args()
|
|
||||||
|
|
||||||
host: str = arguments.host
|
|
||||||
port: int = arguments.port
|
|
||||||
debug_mode: bool = arguments.debug
|
|
||||||
del arguments
|
|
||||||
|
|
||||||
app = Flask('map_server', static_folder='public', static_url_path='/')
|
app = Flask('map_server', static_folder='public', static_url_path='/')
|
||||||
osm_timeout = 3
|
osm_timeout = 3
|
||||||
http_code_ok = 200
|
http_code_ok = 200
|
||||||
|
|
@ -52,8 +40,4 @@ def main():
|
||||||
except urllib.error.URLError as error:
|
except urllib.error.URLError as error:
|
||||||
return f'Cannot retrieve tile: {error}', 501
|
return f'Cannot retrieve tile: {error}', 501
|
||||||
|
|
||||||
app.run(host=host, port=port, debug=debug_mode)
|
return app
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
|
||||||
23
start.py
Normal file
23
start.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
from server import create_app
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument('--host', default='0.0.0.0', help='Server host (default: 0.0.0.0)')
|
||||||
|
parser.add_argument('--port', type=int, default=8000, help='Server port (default: 8000)')
|
||||||
|
parser.add_argument('--debug', action='store_true', help='Run in debug mode (auto-reload on change)')
|
||||||
|
arguments = parser.parse_args()
|
||||||
|
|
||||||
|
host: str = arguments.host
|
||||||
|
port: int = arguments.port
|
||||||
|
debug_mode: bool = arguments.debug
|
||||||
|
del arguments
|
||||||
|
|
||||||
|
app = create_app(debug_mode=debug_mode)
|
||||||
|
app.run(host=host, port=port, debug=debug_mode)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue