Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/synkronus-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
# For PRs: pr-number
type=ref,event=pr
# SHA for traceability (only for non-release events)
type=sha,prefix={{branch}}-,enable=${{ github.event_name != 'release' }}
type=sha,prefix=sha-,enable=${{ github.event_name != 'release' && github.event_name != 'pull_request' }}
labels: |
org.opencontainers.image.title=Synkronus
org.opencontainers.image.description=Synchronization API for offline-first applications
Expand Down
6 changes: 6 additions & 0 deletions synkronus/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/synkronus .

# Copy openapi directory for Swagger UI
COPY --from=builder /app/openapi /app/openapi

# Copy static directory for static files
COPY --from=builder /app/static /app/static

# Create directories for data storage with proper permissions
RUN mkdir -p /app/data/app-bundles && \
chown -R synkronus:synkronus /app
Expand Down
15 changes: 10 additions & 5 deletions synkronus/internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import (
// static files from a http.FileSystem.
func FileServer(r chi.Router, path string, root http.FileSystem) {
if path != "/" && path[len(path)-1] != '/' {
r.Get(path, http.RedirectHandler(path+"/", 301).ServeHTTP)
r.Get(path, http.RedirectHandler(path+"/", http.StatusMovedPermanently).ServeHTTP)
path += "/"
}
r.Get(path+"*", func(w http.ResponseWriter, r *http.Request) {
rctx := chi.RouteContext(r.Context())
pathPrefix := rctx.RoutePattern()
fs := http.StripPrefix(pathPrefix, http.FileServer(root))
fs := http.StripPrefix(path, http.FileServer(root))
fs.ServeHTTP(w, r)
})
}
Expand Down Expand Up @@ -57,6 +55,8 @@ func NewRouter(log *logger.Logger, h *handlers.Handler) http.Handler {
// Public endpoints
r.Get("/health", h.HealthCheck)

r.Get("/openapi/swagger", http.RedirectHandler("/openapi/swagger-ui.html", http.StatusMovedPermanently).ServeHTTP)

// Serve favicon.ico
r.Get("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
// Get the executable directory
Expand All @@ -81,6 +81,11 @@ func NewRouter(log *logger.Logger, h *handlers.Handler) http.Handler {
// Serve static files from the static directory
staticDir := filepath.Join(rootDir, "static")
FileServer(r, "/static", http.Dir(staticDir))

// Serve OpenAPI documentation (Swagger UI)
appDir := filepath.Dir(execDir)
openapiDir := filepath.Join(appDir, "openapi")
FileServer(r, "/openapi", http.Dir(openapiDir))
}

// Authentication routes
Expand Down Expand Up @@ -136,7 +141,7 @@ func NewRouter(log *logger.Logger, h *handlers.Handler) http.Handler {
// User management routes
r.Route("/users", func(r chi.Router) {
// Admin-only routes
r.With(auth.RequireRole(models.RoleAdmin)).Post("/", h.CreateUserHandler)
r.With(auth.RequireRole(models.RoleAdmin)).Post("/create", h.CreateUserHandler)
r.With(auth.RequireRole(models.RoleAdmin)).Delete("/delete/{username}", h.DeleteUserHandler)
r.With(auth.RequireRole(models.RoleAdmin)).Post("/reset-password", h.ResetPasswordHandler)
r.With(auth.RequireRole(models.RoleAdmin)).Get("/", h.ListUsersHandler)
Expand Down
20 changes: 20 additions & 0 deletions synkronus/openapi/swagger-ui.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Synkronus API Documentation</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>

<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
<script>
window.onload = () => {
SwaggerUIBundle({
url: "/openapi/synkronus.yaml",
dom_id: "#swagger-ui",
});
};
</script>
</body>
</html>