feat(api): Enable CORS for multiple API endpoints

This commit is contained in:
Lloyd
2025-12-29 11:05:27 +00:00
parent 2ab4a62011
commit d417fed51a
2 changed files with 25 additions and 0 deletions

1
.gitignore vendored
View File

@@ -48,3 +48,4 @@ identity.json
# Logs
*.log
.DS_Store
syncpi.sh

View File

@@ -185,6 +185,12 @@ class APIEndpoints:
@cherrypy.expose
@cherrypy.tools.json_out()
def send_advert(self):
# Enable CORS for this endpoint
self._set_cors_headers()
if cherrypy.request.method == "OPTIONS":
return ""
try:
self._require_post()
if not self.send_advert_func:
@@ -206,6 +212,12 @@ class APIEndpoints:
@cherrypy.tools.json_out()
@cherrypy.tools.json_in()
def set_mode(self):
# Enable CORS for this endpoint only if configured
self._set_cors_headers()
if cherrypy.request.method == "OPTIONS":
return ""
try:
self._require_post()
data = cherrypy.request.json
@@ -228,6 +240,12 @@ class APIEndpoints:
@cherrypy.tools.json_out()
@cherrypy.tools.json_in()
def set_duty_cycle(self):
# Enable CORS for this endpoint only if configured
self._set_cors_headers()
if cherrypy.request.method == "OPTIONS":
return ""
try:
self._require_post()
data = cherrypy.request.json
@@ -618,6 +636,12 @@ class APIEndpoints:
Returns: {"success": true, "data": {"applied": [...], "live_update": true}}
"""
# Enable CORS for this endpoint only if configured
self._set_cors_headers()
if cherrypy.request.method == "OPTIONS":
return ""
try:
self._require_post()
data = cherrypy.request.json or {}