Example #1
0
def create_app(config=None):
  app = Flask(__name__)

  config = get_config()
  app.config.from_object(config)

  db.init_app(app)

  app = register_endpoints(app)

  @app.errorhandler(404)
  def page_not_found(e):
    import urllib
    output = ""
    for rule in app.url_map.iter_rules():

        options = {}
        for arg in rule.arguments:
            options[arg] = "[{0}]".format(arg)

        methods = ','.join(rule.methods)
        url = url_for(rule.endpoint, **options)
        line = urllib.unquote("{:50s} {:20s} {}".format(rule.endpoint, methods, url))
        line = "<strong>%s</strong> %s %s" % (rule.endpoint, methods, urllib.unquote(url))
        output += "<li>" + line + "</li>"

    return """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

<h3>Current routes:</h3>
<ul>
%s
</ul>
    """ % output, 404

  if 'LOGGING' in app.config:
    configure_logging(app.config['LOGGING'])

  if 'SENTRY_DSN' in app.config:
    sentry = Sentry(dsn=app.config['SENTRY_DSN'], logging=True,
                    level=logging.ERROR)
    sentry.init_app(app)
    app.wsgi = SentryMiddleware(app.wsgi_app, sentry.client)

  return app
Example #2
0
APP.wsgi_app = ProxyFix(APP.wsgi_app)


    
def shutdown():
    """ performs any server shutdown cleanup
    """
    print 'shutting down server ...'
    print 'done'


if __name__ == '__main__':
    APP.debug = False
    APP.trace = False
    APP.wsgi = False
    HOST = '0.0.0.0'
    PORT = 3457  # debugging
    PORT = 4682

    logging.basicConfig(
        stream=sys.stdout,
        level=logging.INFO,
        format='%(asctime)s %(levelname)s %(message)s')

    atexit.register(shutdown)

    for arg in sys.argv[1:]:
        if arg == '--debug':
            APP.debug = True
        if arg == '--trace':
@app.errorhandler(Exception)
def handle_invalid_usage(error):
    print "error", error
    results = { 
        'status': 'internal_error',
        "message": str(error)
    }
    return jsonify(results)

app.wsgi_app = ProxyFix(app.wsgi_app)

if __name__ == '__main__':
    app.debug = False
    app.trace = False
    app.wsgi = False
    for arg in sys.argv[1:]:
        if arg == '--debug':
            app.debug = True
        if arg == '--trace':
            app.trace = True
    if app.debug:
        print 'debug  mode'
        app.run(threaded=False, debug=True)
    elif app.wsgi:
        from gevent.wsgi import WSGIServer
        print 'prod  mode'
        http_server = WSGIServer(('', 5000), app)
        http_server.serve_forever()
    else:
        app.run(threaded=True, debug=False)
    return jsonify(results)


@app.errorhandler(Exception)
def handle_invalid_usage(error):
    print "error", error
    results = {'status': 'internal_error', "message": str(error)}
    return jsonify(results)


app.wsgi_app = ProxyFix(app.wsgi_app)

if __name__ == '__main__':
    app.debug = False
    app.trace = False
    app.wsgi = False
    for arg in sys.argv[1:]:
        if arg == '--debug':
            app.debug = True
        if arg == '--trace':
            app.trace = True
    if app.debug:
        print 'debug  mode'
        app.run(threaded=False, debug=True)
    elif app.wsgi:
        from gevent.wsgi import WSGIServer
        print 'prod  mode'
        http_server = WSGIServer(('', 5000), app)
        http_server.serve_forever()
    else:
        app.run(threaded=True, debug=False)
Example #5
0

APP.wsgi_app = ProxyFix(APP.wsgi_app)


def shutdown():
    """ performs any server shutdown cleanup
    """
    print 'shutting down server ...'
    print 'done'


if __name__ == '__main__':
    APP.debug = False
    APP.trace = False
    APP.wsgi = False
    HOST = '0.0.0.0'
    PORT = 3457  # debugging
    PORT = 4682

    logging.basicConfig(stream=sys.stdout,
                        level=logging.INFO,
                        format='%(asctime)s %(levelname)s %(message)s')

    atexit.register(shutdown)

    for arg in sys.argv[1:]:
        if arg == '--debug':
            APP.debug = True
        if arg == '--trace':
            APP.trace = True