123456789101112131415161718192021222324252627282930 |
- import sqlite3
- import connection
- import server_controller
- import model
- from bottle import run, request, response, route
- from server_controller import not_found
- from util import debug
- if __name__ == '__main__':
- print('sqlite3.version', model.db.version)
- model.setup()
- valid_routes = ['login', 'register']
- @route('/<path>', method='POST')
- def process(path):
- if path not in valid_routes:
- return not_found()
- response.content_type = 'application/json'
- method_to_call = getattr(server_controller, path)
- try:
- return method_to_call()
- except sqlite3.IntegrityError:
- return server_controller.bad_request('action violates database constraints')
- run(host='localhost', port=connection.port, debug=debug)
|