server.py 747 B

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