Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions apiserver/frontend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"embed"
"io/fs"
"net/http"
"strings"

config "dkhalife.com/tasks/core/config"
"github.com/gin-gonic/gin"
Expand All @@ -12,6 +13,8 @@ import (
//go:embed dist
var embeddedFiles embed.FS

var publicPaths = []string{"/login", "/privacy"}

type Handler struct {
ServeFrontend bool
}
Expand All @@ -29,6 +32,15 @@ func Routes(router *gin.Engine, h *Handler) {
}
}

func isPublicPath(path string) bool {
for _, p := range publicPaths {
if strings.HasPrefix(path, p) {
return true
}
}
return false
Comment thread
dkhalife marked this conversation as resolved.
}

func staticMiddleware(root string) gin.HandlerFunc {
fileServer := http.FileServer(getFileSystem(root))

Expand All @@ -46,6 +58,15 @@ func staticMiddlewareNoRoute(root string) gin.HandlerFunc {
fileServer := http.FileServer(getFileSystem(root))

return func(c *gin.Context) {
if !isPublicPath(c.Request.URL.Path) {
target := "/login"
if q := c.Request.URL.RawQuery; q != "" {
target += "?" + q
}
c.Redirect(http.StatusFound, target)
return
Comment thread
dkhalife marked this conversation as resolved.
Outdated
}

c.Request.URL.Path = "/"
fileServer.ServeHTTP(c.Writer, c.Request)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/msal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const doInitializeMsal = async () => {
auth: {
clientId: authConfig.client_id,
authority: `https://login.microsoftonline.com/${authConfig.tenant_id}`,
redirectUri: window.location.origin,
redirectUri: `${window.location.origin}/login`,
},
cache: {
cacheLocation: 'localStorage',
Expand Down
Loading