From 8a34fb6dc2f2761b65dfdcfbde8fdebdc5e2e0db Mon Sep 17 00:00:00 2001 From: Gabriel Levcovitz Date: Tue, 14 Jan 2025 13:33:25 -0300 Subject: [PATCH] fix: add OPTIONS /submit-job endpoint for CORS (#123) --- txstratum/api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/txstratum/api.py b/txstratum/api.py index b1bdd30..451b539 100644 --- a/txstratum/api.py +++ b/txstratum/api.py @@ -83,6 +83,8 @@ def __init__( self.app.router.add_get("/health", self.health) self.app.router.add_get("/mining-status", self.mining_status) self.app.router.add_get("/job-status", self.job_status) + self.app.router.add_options("/submit-job", self.get_options_response) + self.app.router.add_options("/cancel-job", self.get_options_response) self.app.router.add_post("/submit-job", self.submit_job) self.app.router.add_post("/cancel-job", self.cancel_job) @@ -120,6 +122,14 @@ async def mining_status(self, request: web.Request) -> web.Response: """Return status of miners.""" return web.json_response(self.manager.status()) + async def get_options_response(self, request: web.Request) -> web.Response: + """ + Return empty success response. + + This endpoint is required to make CORS work when using the desktop wallet with a local tx-mining-service. + """ + return web.json_response("{}", status=200) + async def submit_job(self, request: web.Request) -> web.Response: """Submit a new tx job to the manager.