Advertisement
Guest User

Untitled

a guest
May 23rd, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. import json
  2. import logging
  3. from collections import OrderedDict
  4.  
  5. import falcon
  6. from tinydb import TinyDB, where
  7.  
  8. db = TinyDB('db.json')
  9.  
  10. logger = logging.getLogger(__file__.split('.', 1)[0])
  11. logging.basicConfig(format='[{levelname} {name} {funcName}] {message}', style='{')
  12. logger.setLevel(logging.INFO)
  13.  
  14.  
  15. class CORSComponent(object):
  16.  
  17.     def process_response(self, req, resp, resource, req_succeeded):
  18.         resp.set_header('Access-Control-Allow-Origin', '*')
  19.  
  20.         if (req_succeeded and req.method == 'OPTIONS' and req.get_header('Access-Control-Request-Method')):
  21.  
  22.             allow = resp.get_header('Allow')
  23.             resp.delete_header('Allow')
  24.  
  25.             allow_headers = req.get_header('Access-Control-Request-Headers', default='*')
  26.  
  27.             resp.set_headers((
  28.                 ('Access-Control-Allow-Methods', allow),
  29.                 ('Access-Control-Allow-Headers', allow_headers),
  30.                 ('Access-Control-Max-Age', '86400'),  # 24 hours
  31.             ))
  32.  
  33.  
  34. class Stats:
  35.  
  36.     def on_get(self, req, resp):
  37.         pass
  38.  
  39.     def on_post(self, req, resp):
  40.         pass
  41.  
  42. app = falcon.API(middleware=[CORSComponent()])
  43. app.req_options.strip_url_path_trailing_slash = True
  44. app.req_options.auto_parse_form_urlencoded = True
  45.  
  46. app.add_route('/SomeGame/stats', Stats())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement