@app.errorhandler(404) def not_found(error): """ error handler """ LOG.error(error) return make_response(jsonify({'error': 'Not found'}), 404) @app.errorhandler(405) def method_not_allowed(error): """ error handler """ LOG.error(error) return make_response(jsonify({'error': 'Method not allowed'}), 405) @app.errorhandler(500) def server_error(error): """ error handler """ LOG.error(error) return make_response(jsonify({error}), 500) @app.errorhandler(Exception) def exception_handler(error): print("error",str(repr(error))) LOG.error(error) return make_response(jsonify(error = str(repr(error)) ), 500) #return "!!!!" + str(repr(error)) if __name__ == '__main__': LOG.info('running in port: %s', os.environ.get('PORT')) app.run(host='0.0.0.0', port=int(PORT))
# -*- coding:utf-8 -*- __author__ = 'charleszhu' from modules.app import app if __name__ == '__main__': app.run()
# Port variable to run the server on. PORT = get_env_or_default('PORT', '8080') @app.errorhandler(404) def not_found(error): """ error handler """ LOG.error(error) return make_response(jsonify({'error': 'Not found'}), 404) @app.route('/') def index(): """ static files serve """ return send_from_directory('dist', 'index.html') @app.route('/<path:path>') def static_proxy(path): """ static folder serve """ file_name = path.split('/')[-1] dir_name = os.path.join('dist', '/'.join(path.split('/')[:-1])) return send_from_directory(dir_name, file_name) if __name__ == '__main__': LOG.info('running environment: %s', os.environ.get('ENV')) app.config['DEBUG'] = os.environ.get('ENV') == 'development' # Debug mode if development env app.run(host='0.0.0.0', port=int(PORT)) # Run the app
''' index file for Flask API ''' import os from modules.app import app from modules import logger if __name__ == "__main__": HOST = None _containerd = os.environ.get('FLASK_RUNNING_IN_DOCKER') if _containerd and _containerd == 'true': HOST = '0.0.0.0' PORT = os.environ.get('PORT') if PORT: PORT = int(PORT) else: PORT = 5001 app.run(host=HOST, port=PORT)
from modules.app import app if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=True)