server.py 799 B

123456789101112131415161718192021222324252627282930
  1. import sqlite3
  2. import connection
  3. import server_controller
  4. import model
  5. from bottle import run, request, response, route
  6. from server_controller import not_found
  7. from util import debug
  8. if __name__ == '__main__':
  9. print('sqlite3.version', model.db.version)
  10. model.setup()
  11. valid_routes = ['login', 'register']
  12. @route('/<path>', method='POST')
  13. def process(path):
  14. if path not in valid_routes:
  15. return not_found()
  16. response.content_type = 'application/json'
  17. method_to_call = getattr(server_controller, path)
  18. try:
  19. return method_to_call()
  20. except sqlite3.IntegrityError:
  21. return server_controller.bad_request('action violates database constraints')
  22. run(host='localhost', port=connection.port, debug=debug)