def RunFileServer(fileServerDir, fileServerPort):
"""
Run a Flask file server on the given port.
Explicitly specify instance_path, because Flask's
auto_find_instance_path can fail when run in a frozen app.
"""
app = Flask(__name__, instance_path=fileServerDir)
@app.route('/fileserver-is-ready', methods=['GET'])
def FileserverIsReady(): # pylint: disable=unused-variable
"""
Used to test if file server has started.
"""
return 'Fileserver is ready!'
@app.route('/<path:filename>', methods=['GET'])
def ServeFile(filename): # pylint: disable=unused-variable
"""
Serves up a file from PYUPDATER_FILESERVER_DIR.
"""
return send_from_directory(fileServerDir, filename.strip('/'))
def ShutDownServer():
"""
Shut down the file server.
"""
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
@app.route('/shutdown', methods=['POST'])
def ShutDown(): # pylint: disable=unused-variable
"""
Respond to a POSTed request to shut down the file server.
"""
ShutDownServer()
return 'Server shutting down...'
app.run(host=LOCALHOST, port=fileServerPort)
评论列表
文章目录