|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
from apistar import Route
|
|
|
|
|
from apistar.http import HTMLResponse
|
|
|
|
|
from apistar import Route, App
|
|
|
|
|
from apistar_jwt import JWT
|
|
|
|
|
from apistar_mail import MailComponent
|
|
|
|
|
import logbook
|
|
|
|
@ -7,9 +6,9 @@ from sqlalchemy import create_engine
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
from cookie_api.auth import auth_routes
|
|
|
|
|
from cookie_api.logger import global_init
|
|
|
|
|
from cookie_api.logger import init_logging
|
|
|
|
|
from cookie_api.resources import cookie_routes
|
|
|
|
|
from cookie_api.util import SQLAlchemyHook, SQLAlchemySession, MetaApp as App
|
|
|
|
|
from cookie_api.util import SQLAlchemyHook, SQLAlchemySession
|
|
|
|
|
|
|
|
|
|
BASEDIR = Path(__file__).parent
|
|
|
|
|
TEMPLATE_DIR = BASEDIR.joinpath('templates')
|
|
|
|
@ -17,18 +16,15 @@ STATIC_DIR = BASEDIR.joinpath('static')
|
|
|
|
|
|
|
|
|
|
logger = logbook.Logger(__name__)
|
|
|
|
|
|
|
|
|
|
engine = create_engine('postgresql://apistar@localhost:5432/apistar')
|
|
|
|
|
|
|
|
|
|
app_settings = {
|
|
|
|
|
"LOGGING": {
|
|
|
|
|
"LEVEL": "DEBUG"
|
|
|
|
|
"LEVEL": "INFO"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def return_index_html():
|
|
|
|
|
with open(STATIC_DIR.joinpath('index.html'), mode='rb') as f:
|
|
|
|
|
return HTMLResponse(content=f.read())
|
|
|
|
|
def return_index_html(app: App):
|
|
|
|
|
return app.render_template('index.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
index = Route('/', 'GET', return_index_html)
|
|
|
|
@ -38,7 +34,7 @@ _routes = cookie_routes + auth_routes + [index]
|
|
|
|
|
_hooks = [SQLAlchemyHook]
|
|
|
|
|
|
|
|
|
|
_components = [
|
|
|
|
|
SQLAlchemySession(engine=engine),
|
|
|
|
|
SQLAlchemySession(engine=create_engine('postgresql://apistar@localhost:5432/apistar')),
|
|
|
|
|
JWT({
|
|
|
|
|
'JWT_USER_ID': 'sub',
|
|
|
|
|
'JWT_SECRET': 'thisisasecret',
|
|
|
|
@ -60,7 +56,8 @@ def application_factory(routes=_routes, components=_components, hooks=_hooks, se
|
|
|
|
|
"""Returns an instance of Cookie API"""
|
|
|
|
|
_settings = {**app_settings, **settings}
|
|
|
|
|
|
|
|
|
|
global_init(_settings)
|
|
|
|
|
init_logging(_settings)
|
|
|
|
|
|
|
|
|
|
logger.debug("Template directory {}".format(template_dir))
|
|
|
|
|
logger.debug("Static directory {}".format(STATIC_DIR))
|
|
|
|
|
|
|
|
|
|