35 lines
885 B
Python
35 lines
885 B
Python
from bottle import request, Bottle
|
|
|
|
from simple_chat_api.db_handler import DbConnector
|
|
|
|
import simple_chat_api.endpoints.auth as auth
|
|
import simple_chat_api.endpoints.messages as messages
|
|
import simple_chat_api.config as config
|
|
|
|
import bcrypt
|
|
# Needet because of: https://github.com/pyca/bcrypt/issues/684
|
|
if not hasattr(bcrypt, '__about__'):
|
|
bcrypt.__about__ = type('about', (object,), {'__version__': bcrypt.__version__})
|
|
|
|
app = Bottle()
|
|
|
|
|
|
def initialize_app():
|
|
db = DbConnector(config.db_url)
|
|
|
|
@app.hook('before_request')
|
|
def attach_resources():
|
|
request.db_connector = db
|
|
body = request.body.read()
|
|
|
|
return app
|
|
|
|
def main():
|
|
initialize_app()
|
|
|
|
app.mount('/user', auth.app)
|
|
app.mount('/messages', messages.app)
|
|
|
|
root_app = Bottle()
|
|
root_app.mount('/api', app)
|
|
root_app.run(host='localhost', port=7000, debug=config.debug) |