4242# Needed for initialization. Do not remove.
4343import cmsranking .Logger # noqa
4444from cmscommon .eventsource import EventSource
45- from cmsranking .Config import load_config
45+ from cmsranking .Config import PublicConfig , load_config
4646from cmsranking .Contest import Contest
4747from cmsranking .Entity import InvalidData
4848from cmsranking .Scoring import ScoringStore
@@ -473,6 +473,32 @@ def wsgi_app(self, environ, start_response):
473473 return response
474474
475475
476+ class PublicConfigHandler :
477+
478+ def __init__ (self , pub_config : PublicConfig ):
479+ self .pub_config = pub_config
480+
481+ def __call__ (self , environ , start_response ):
482+ return self .wsgi_app (environ , start_response )
483+
484+ @responder
485+ def wsgi_app (self , environ , start_response ):
486+ request = Request (environ )
487+ request .encoding_errors = "strict"
488+
489+ response = Response ()
490+ response .status_code = 200
491+ response .mimetype = "application/json"
492+ print (str (self .pub_config ))
493+ response .data = json .dumps (
494+ self .pub_config ,
495+ default = lambda o : o .__dict__ ,
496+ sort_keys = True ,
497+ )
498+
499+ return response
500+
501+
476502class RoutingHandler :
477503
478504 def __init__ (
@@ -482,20 +508,23 @@ def __init__(
482508 logo_handler : ImageHandler ,
483509 score_handler : ScoreHandler ,
484510 history_handler : HistoryHandler ,
511+ public_config_handler : PublicConfigHandler ,
485512 ):
486513 self .router = Map ([
487514 Rule ("/" , methods = ["GET" ], endpoint = "root" ),
488515 Rule ("/history" , methods = ["GET" ], endpoint = "history" ),
489516 Rule ("/scores" , methods = ["GET" ], endpoint = "scores" ),
490517 Rule ("/events" , methods = ["GET" ], endpoint = "events" ),
491518 Rule ("/logo" , methods = ["GET" ], endpoint = "logo" ),
519+ Rule ("/config" , methods = ["GET" ], endpoint = "public_config" )
492520 ], encoding_errors = "strict" )
493521
494522 self .event_handler = event_handler
495523 self .logo_handler = logo_handler
496524 self .score_handler = score_handler
497525 self .history_handler = history_handler
498526 self .root_handler = root_handler
527+ self .public_config_handler = public_config_handler
499528
500529 def __call__ (self , environ , start_response ):
501530 return self .wsgi_app (environ , start_response )
@@ -517,6 +546,8 @@ def wsgi_app(self, environ, start_response):
517546 return self .score_handler (environ , start_response )
518547 elif endpoint == "history" :
519548 return self .history_handler (environ , start_response )
549+ elif endpoint == 'public_config' :
550+ return self .public_config_handler (environ , start_response )
520551
521552
522553def main () -> int :
@@ -593,7 +624,8 @@ def main() -> int:
593624 os .path .join (config .lib_dir , '%(name)s' ),
594625 os .path .join (web_dir , 'img' , 'logo.png' )),
595626 ScoreHandler (stores ),
596- HistoryHandler (stores ))
627+ HistoryHandler (stores ),
628+ PublicConfigHandler (config .public ))
597629
598630 wsgi_app = SharedDataMiddleware (DispatcherMiddleware (
599631 toplevel_handler , {
0 commit comments