コード例 #1
0
ファイル: main.py プロジェクト: kirill-kundik/Place-for-work
async def init_app(argv=None):
    app = web.Application()

    print('...Reading configs...')
    app['config'] = get_config(argv)

    # setup Jinja2 template renderer
    print('...Set up jinja2...')
    aiohttp_jinja2.setup(app,
                         loader=jinja2.PackageLoader('backend', 'templates'))

    # create db connection on startup, shutdown on exit
    print('...Appending startup tasks...')
    app.on_startup.append(init_pg)
    app.on_startup.append(init_security)
    app.on_cleanup.append(close_pg)
    print('...Set up ElasticSearch...')
    app.on_startup.append(init_es)
    app.on_cleanup.append(close_es)

    # setup views and routes
    print('...Set up routes...')
    setup_routes(app)
    print('...Set up middlewares...')
    setup_middlewares(app)

    return app
コード例 #2
0
ファイル: main.py プロジェクト: kirill-kundik/Place-for-work
def main(argv):
    # init_db()  # if needed to initialize db or drop all data

    logging.basicConfig(level=logging.DEBUG)

    app = init_app(argv)

    config = get_config(argv)
    print('...Starting app...')
    web.run_app(app, host=config['host'], port=config['port'])
コード例 #3
0
def create_app() -> Flask:
    app = Flask(__name__)

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

    firebase.init_app(app)
    mongo.init_app(app)
    app.register_blueprint(users)
    app.register_blueprint(texts)

    return app
コード例 #4
0
from db.models import *
from backend.settings import BASE_DIR, get_config
from db.sample_data import get_sample_news, get_sample_categories

DSN = "postgresql://{user}:{password}@{host}:{port}/{database}"

ADMIN_DB_URL = DSN.format(
    user='******', password='******', database='postgres',
    host='postgres', port=5432
)

admin_engine = create_engine(ADMIN_DB_URL, isolation_level='AUTOCOMMIT')

USER_CONFIG_PATH = BASE_DIR / 'config' / 'workplace.yaml'
USER_CONFIG = get_config(['-c', USER_CONFIG_PATH.as_posix()])
USER_DB_URL = DSN.format(**USER_CONFIG['postgres'])
user_engine = create_engine(USER_DB_URL)

TEST_CONFIG_PATH = BASE_DIR / 'config' / 'workplace_test.yaml'
TEST_CONFIG = get_config(['-c', TEST_CONFIG_PATH.as_posix()])
TEST_DB_URL = DSN.format(**TEST_CONFIG['postgres'])
test_engine = create_engine(TEST_DB_URL)


def setup_db(config):
    db_name = config['database']
    db_user = config['user']
    db_pass = config['password']

    conn = admin_engine.connect()
コード例 #5
0
from flask import Flask, render_template
from flask_webpack import Webpack
from backend.settings import get_config

app = Flask(__name__, static_folder='../static')
config = get_config()

app.config.update({
    'WEBPACK_MANIFEST_PATH': '../static/manifest.json',
    'DEBUG': config['debug'],
})
webpack = Webpack()
webpack.init_app(app)


@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
    return render_template('index.jinja2')