mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Add apidocs endpoint. Closes #1
This commit is contained in:
@@ -28,6 +28,7 @@ class WebServer:
|
||||
bottle.get("/api/spots")(self.serve_api_spots)
|
||||
bottle.get("/api/status")(self.serve_api_status)
|
||||
bottle.get("/")(self.serve_index)
|
||||
bottle.get("/apidocs")(self.serve_apidocs)
|
||||
bottle.get("/<filepath:path>")(self.serve_static_file)
|
||||
|
||||
# Start the web server
|
||||
@@ -62,6 +63,13 @@ class WebServer:
|
||||
self.status = "OK"
|
||||
return bottle.static_file("index.html", root="webassets")
|
||||
|
||||
# Serve the API docs page. This would be accessible as /apidocs/index.html but we need this workaround to make it
|
||||
# available as /apidocs
|
||||
def serve_apidocs(self):
|
||||
self.last_page_access_time = datetime.now(pytz.UTC)
|
||||
self.status = "OK"
|
||||
return bottle.static_file("index.html", root="webassets/apidocs")
|
||||
|
||||
# Serve general static files from "webassets" directory
|
||||
def serve_static_file(self, filepath):
|
||||
return bottle.static_file(filepath, root="webassets")
|
||||
|
||||
11
webassets/apidocs/index.html
Normal file
11
webassets/apidocs/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>API Documentation</title>
|
||||
</head>
|
||||
<body>
|
||||
<redoc spec-url="/apidocs/openapi.yml"></redoc>
|
||||
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user