Beispiel #1
0
def create_app():
    logging.basicConfig(level=logging.DEBUG)
    app = Flask(__name__)
    app.config.from_object('api.default.settings')
    app.db = DBAPI(globals.DB_MIN_CONN, globals.DB_MAX_CONN, dsn=globals.DSN)

    logger.debug('Starting RESTful API on URL {}'.format(globals.REST_URL))
    app.register_blueprint(rest, url_prefix=globals.REST_URL)

    logger.debug('Starting SOAP API on URL {}'.format(globals.SOAP_URL))
    app.wsgi_app = DispatcherMiddleware(app.wsgi_app,
            {globals.SOAP_URL : create_soap_wsgi(app.db)})

    app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)
    return app
Beispiel #2
0
from flask import Flask, session, redirect, url_for, escape, request

from werkzeug.contrib.fixers import LighttpdCGIRootFix

app = Flask(__name__)

app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)


@app.route('/')
def index():
    if 'username' in session:
        return 'Logged in as %s' % escape(session['username'])
    return 'You are not logged in'


@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        session['username'] = request.form['username']
        return redirect(url_for('index'))
    return '''
        <form action="" method="post">
            <p><input type=text name=username>
            <p><input type=submit value=Login>
        </form>
    '''


@app.route('/logout')
def logout():
Beispiel #3
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        AUTHORIZATION_KEY_RAW='devauthkey',
        DATABASE=os.path.join(app.instance_path, 'bikeshed.db'),
        # TODO was UPLOAD_FOLDER = '/var/www/rawdata/db/'
        UPLOAD_FOLDER=os.path.join(app.instance_path, 'data'),
        USER_FOLDER=os.path.join(app.instance_path, 'user'),
        MAX_CONTENT_LENGTH=6000 * 1024 * 1024,  # 6 GB
        WEBSITE_VERSION='0.0.0w',
        APPLICATION_VERSION='0.0.0a',
    )
    from werkzeug.contrib.fixers import LighttpdCGIRootFix
    app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        # BIKESHED_SETTINGS=/dir/config.py from environment
        app.config.from_envvar('BIKESHED_SETTINGS', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    app.config.update(
        AUTHORIZATION_KEY=generate_password_hash(
            app.config['AUTHORIZATION_KEY_RAW']),
        AUTHORIZATION_KEY_RAW='',
    )

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    try:
        os.makedirs(app.config['UPLOAD_FOLDER'])
    except OSError:
        pass

    try:
        os.makedirs(app.config['USER_FOLDER'])
    except OSError:
        pass

    # a simple page that says hello
    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    # pass-through for Let's Encrypt updates which are installed in the
    # /.well-known/ static directory
    @app.route('/.well-known/acme-challenge/<path:path>')
    @app.route('/api/.well-known/acme-challenge/<path:path>')
    def send_letsencrypt(path):
        root = os.path.join(app.root_path, '..', '.well-known',
                            'acme-challenge')
        return send_from_directory(root, path)

    from . import db
    db.init_app(app)

    from . import auth
    app.register_blueprint(auth.bp)

    from . import cover
    app.register_blueprint(cover.bp)
    app.add_url_rule('/', endpoint='index')

    from . import upload
    app.register_blueprint(upload.bp)

    from . import api
    app.register_blueprint(api.bp)

    return app