Skip to content

Commit 7de625f

Browse files
Fix Swagger UI OpenAPI spec loading with dynamic base path
- Update Swagger UI to detect base path from current URL - Copy api directory to Docker image for OpenAPI spec access - Fixes 404 error when loading /api/openapi.yaml in production
1 parent b74188b commit 7de625f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

apps/semcache-service/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ WORKDIR /app
2929
# Copy binary from builder
3030
COPY --from=builder /app/server .
3131

32+
# Copy API documentation files
33+
COPY --from=builder /app/api ./api
34+
3235
# Expose port
3336
EXPOSE 8080
3437

apps/semcache-service/internal/handlers/swagger.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ func (h *Handler) ServeSwaggerUI(c echo.Context) error {
4747
<script src="https://unpkg.com/[email protected]/swagger-ui-standalone-preset.js"></script>
4848
<script>
4949
window.onload = function() {
50+
// Get the base path from the current URL
51+
const basePath = window.location.pathname.replace(/\/docs$/, '');
52+
const specUrl = basePath + '/api/openapi.yaml';
53+
5054
const ui = SwaggerUIBundle({
51-
url: "/api/openapi.yaml",
55+
url: specUrl,
5256
dom_id: '#swagger-ui',
5357
deepLinking: true,
5458
presets: [

0 commit comments

Comments
 (0)