Add host parameter and loglevel in non-debug mode
This commit is contained in:
parent
36956e14bf
commit
c59f8f7edb
1 changed files with 7 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
@ -8,10 +9,12 @@ from flask import Flask, send_file
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = ArgumentParser()
|
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('--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)')
|
parser.add_argument('--debug', action='store_true', help='Run in debug mode (auto-reload on change)')
|
||||||
arguments = parser.parse_args()
|
arguments = parser.parse_args()
|
||||||
|
|
||||||
|
host: str = arguments.host
|
||||||
port: int = arguments.port
|
port: int = arguments.port
|
||||||
debug_mode: bool = arguments.debug
|
debug_mode: bool = arguments.debug
|
||||||
del arguments
|
del arguments
|
||||||
|
|
@ -19,6 +22,9 @@ def main():
|
||||||
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
|
||||||
|
if not debug_mode:
|
||||||
|
log = logging.getLogger('werkzeug')
|
||||||
|
log.setLevel(logging.WARNING)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def _index():
|
def _index():
|
||||||
|
|
@ -46,7 +52,7 @@ 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='0.0.0.0', port=port, debug=debug_mode)
|
app.run(host=host, port=port, debug=debug_mode)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue