mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-06-24 05:35:10 +00:00
Stop fudging the server-side handling instructions for "add spot" into the spot data structure itself, instead break them out into a new area. This is a breaking change to the API so all API endpoints have been bumped to v2.
This commit is contained in:
@@ -8,6 +8,7 @@ from tornado.web import StaticFileHandler
|
||||
from core.config import ALLOW_SPOTTING, WEB_SERVER_PORT, API_ONLY_MODE
|
||||
from core.utils import empty_queue
|
||||
from server.handlers.api.addspot import APISpotHandler
|
||||
from server.handlers.api.v1_compatability import V1RedirectHandler, V1GoneHandler
|
||||
from server.handlers.api.alerts import APIAlertsHandler, APIAlertsStreamHandler
|
||||
from server.handlers.api.dxstats import APIDxStatsHandler
|
||||
from server.handlers.api.lookups import APILookupCallHandler, APILookupSIGRefHandler, APILookupGridHandler
|
||||
@@ -64,24 +65,31 @@ class WebServer:
|
||||
|
||||
# API endpoints are always enabled
|
||||
api_routes = [
|
||||
(r"/api/v1/spots", APISpotsHandler, {"spots": self._spots, **handler_opts}),
|
||||
(r"/api/v1/alerts", APIAlertsHandler, {"alerts": self._alerts, **handler_opts}),
|
||||
(r"/api/v1/spots/stream", APISpotsStreamHandler,
|
||||
(r"/api/v2/spots", APISpotsHandler, {"spots": self._spots, **handler_opts}),
|
||||
(r"/api/v2/alerts", APIAlertsHandler, {"alerts": self._alerts, **handler_opts}),
|
||||
(r"/api/v2/spots/stream", APISpotsStreamHandler,
|
||||
{"sse_spot_queues": self._sse_spot_queues, **handler_opts}),
|
||||
(r"/api/v1/alerts/stream", APIAlertsStreamHandler,
|
||||
(r"/api/v2/alerts/stream", APIAlertsStreamHandler,
|
||||
{"sse_alert_queues": self._sse_alert_queues, **handler_opts}),
|
||||
(r"/api/v1/solar", APISolarConditionsHandler, {"solar_conditions": self._solar_conditions, **handler_opts}),
|
||||
(r"/api/v1/dxstats", APIDxStatsHandler, {"spots": self._spots, **handler_opts}),
|
||||
(r"/api/v1/options", APIOptionsHandler,
|
||||
(r"/api/v2/solar", APISolarConditionsHandler, {"solar_conditions": self._solar_conditions, **handler_opts}),
|
||||
(r"/api/v2/dxstats", APIDxStatsHandler, {"spots": self._spots, **handler_opts}),
|
||||
(r"/api/v2/options", APIOptionsHandler,
|
||||
{"status_data": self._status_data, "spot_providers": self._spot_providers, **handler_opts}),
|
||||
(r"/api/v1/status", APIStatusHandler, {"status_data": self._status_data, **handler_opts}),
|
||||
(r"/api/v1/lookup/call", APILookupCallHandler, {**handler_opts}),
|
||||
(r"/api/v1/lookup/sigref", APILookupSIGRefHandler, {**handler_opts}),
|
||||
(r"/api/v1/lookup/grid", APILookupGridHandler, {**handler_opts}),
|
||||
(r"/api/v1/spot", APISpotHandler,
|
||||
(r"/api/v2/status", APIStatusHandler, {"status_data": self._status_data, **handler_opts}),
|
||||
(r"/api/v2/lookup/call", APILookupCallHandler, {**handler_opts}),
|
||||
(r"/api/v2/lookup/sigref", APILookupSIGRefHandler, {**handler_opts}),
|
||||
(r"/api/v2/lookup/grid", APILookupGridHandler, {**handler_opts}),
|
||||
(r"/api/v2/spot", APISpotHandler,
|
||||
{"spots": self._spots, "spot_providers": self._spot_providers, **handler_opts}),
|
||||
]
|
||||
|
||||
# v1 API redirects. Most v1 enpoints are unchanged in v2, and get an HTTP 308 redirect to the v2 API. The ones
|
||||
# that have the actual breaking changes get a bespoke handler.
|
||||
v1_compat_routes = [
|
||||
(r"/api/v1/spot", V1GoneHandler),
|
||||
(r"/api/v1/(.*)", V1RedirectHandler),
|
||||
]
|
||||
|
||||
# If in API-only mode, serve a basic homepage; in normal mode, serve the usual UI routes
|
||||
if self._api_only_mode:
|
||||
logging.info("API-only mode is enabled. Web UI will not be served.")
|
||||
@@ -109,7 +117,7 @@ class WebServer:
|
||||
(r"/(.*)", StaticFileHandler, {"path": os.path.join(_HERE, "../webassets")})
|
||||
]
|
||||
|
||||
app = tornado.web.Application(api_routes + ui_routes + misc_routes,
|
||||
app = tornado.web.Application(api_routes + v1_compat_routes + ui_routes + misc_routes,
|
||||
template_path=os.path.join(_HERE, "../templates"),
|
||||
debug=False)
|
||||
app.listen(self._port)
|
||||
|
||||
Reference in New Issue
Block a user