Compare commits

..

9 Commits

Author SHA1 Message Date
CzBiX
76f2014444 feat: add http cache for static files (#395)
* feat: add http cache for static files

fix #392

* minor typo fix
2025-10-08 18:58:22 +03:00
Stavros
5b7bda3378 chore: use bun frozen lockfile for builds 2025-10-08 18:56:42 +03:00
Stavros
e878516130 refactor: don't add tinyauth suffix to title 2025-10-08 16:41:41 +03:00
Stavros
e5f1df03c4 feat: add tinyauth to container path 2025-10-08 16:40:22 +03:00
Stavros
c77da30d87 refactor: set gin mode using env 2025-10-08 16:24:14 +03:00
Stavros
287c6f975f fix: do not allow request if docker labels check fail 2025-10-08 15:44:34 +03:00
Stavros
0255e954f7 refactor: use non-google specific meta tags 2025-10-08 15:42:52 +03:00
Stavros
c5d70d7c93 feat: set page title based on configured title 2025-10-08 15:35:54 +03:00
Stavros
adffb4ac0a fix: names in oauth broker 2025-10-08 15:15:30 +03:00
13 changed files with 59 additions and 39 deletions

View File

@@ -23,7 +23,7 @@ jobs:
- name: Install frontend dependencies
run: |
cd frontend
bun install
bun install --frozen-lockfile
- name: Set version
run: |

View File

@@ -66,7 +66,7 @@ jobs:
- name: Install frontend dependencies
run: |
cd frontend
bun install
bun install --frozen-lockfile
- name: Install backend dependencies
run: |
@@ -112,7 +112,7 @@ jobs:
- name: Install frontend dependencies
run: |
cd frontend
bun install
bun install --frozen-lockfile
- name: Install backend dependencies
run: |

View File

@@ -44,7 +44,7 @@ jobs:
- name: Install frontend dependencies
run: |
cd frontend
bun install
bun install --frozen-lockfile
- name: Install backend dependencies
run: |
@@ -87,7 +87,7 @@ jobs:
- name: Install frontend dependencies
run: |
cd frontend
bun install
bun install --frozen-lockfile
- name: Install backend dependencies
run: |

View File

@@ -6,7 +6,7 @@ WORKDIR /frontend
COPY ./frontend/package.json ./
COPY ./frontend/bun.lock ./
RUN bun install
RUN bun install --frozen-lockfile
COPY ./frontend/public ./public
COPY ./frontend/src ./src
@@ -51,6 +51,10 @@ EXPOSE 3000
VOLUME ["/data"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD ["/tinyauth/tinyauth", "healthcheck"]
ENV GIN_MODE=release
ENTRYPOINT ["/tinyauth/tinyauth"]
ENV PATH=$PATH:/tinyauth
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD ["tinyauth", "healthcheck"]
ENTRYPOINT ["tinyauth"]

View File

@@ -6,7 +6,7 @@ WORKDIR /frontend
COPY ./frontend/package.json ./
COPY ./frontend/bun.lock ./
RUN bun install
RUN bun install --frozen-lockfile
COPY ./frontend/public ./public
COPY ./frontend/src ./src
@@ -51,6 +51,10 @@ EXPOSE 3000
VOLUME ["/data"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD ["/tinyauth/tinyauth", "healthcheck"]
ENV GIN_MODE=release
ENTRYPOINT ["/tinyauth/tinyauth"]
ENV PATH=$PATH:/tinyauth
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD ["tinyauth", "healthcheck"]
ENTRYPOINT ["tinyauth"]

View File

@@ -8,7 +8,7 @@
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<meta name="apple-mobile-web-app-title" content="Tinyauth" />
<meta name="robots" content="none" />
<meta name="robots" content="nofollow, noindex" />
<link rel="manifest" href="/site.webmanifest" />
<title>Tinyauth</title>
</head>

View File

@@ -1,11 +1,15 @@
import { useAppContext } from "@/context/app-context";
import { LanguageSelector } from "../language/language";
import { Outlet } from "react-router";
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { DomainWarning } from "../domain-warning/domain-warning";
const BaseLayout = ({ children }: { children: React.ReactNode }) => {
const { backgroundImage } = useAppContext();
const { backgroundImage, title } = useAppContext();
useEffect(() => {
document.title = title;
}, [title]);
return (
<div

View File

@@ -150,18 +150,6 @@ func (app *BootstrapApp) Setup() error {
configuredProviders := make([]controller.Provider, 0)
for id, provider := range oauthProviders {
if id == "" {
continue
}
if provider.Name == "" {
if name, ok := config.OverrideProviders[id]; ok {
provider.Name = name
} else {
provider.Name = utils.Capitalize(id)
}
}
configuredProviders = append(configuredProviders, controller.Provider{
Name: provider.Name,
ID: id,
@@ -184,10 +172,6 @@ func (app *BootstrapApp) Setup() error {
}
// Create engine
if config.Version != "development" {
gin.SetMode(gin.ReleaseMode)
}
engine := gin.New()
if len(app.config.TrustedProxies) > 0 {

View File

@@ -1,10 +1,12 @@
package middleware
import (
"fmt"
"io/fs"
"net/http"
"os"
"strings"
"time"
"tinyauth/internal/assets"
"github.com/gin-gonic/gin"
@@ -27,14 +29,16 @@ func (m *UIMiddleware) Init() error {
}
m.uiFs = ui
m.uiFileServer = http.FileServer(http.FS(ui))
m.uiFileServer = http.FileServerFS(ui)
return nil
}
func (m *UIMiddleware) Middleware() gin.HandlerFunc {
return func(c *gin.Context) {
switch strings.Split(c.Request.URL.Path, "/")[1] {
path := strings.TrimPrefix(c.Request.URL.Path, "/")
switch strings.SplitN(path, "/", 2)[0] {
case "api":
c.Next()
return
@@ -42,12 +46,19 @@ func (m *UIMiddleware) Middleware() gin.HandlerFunc {
c.Next()
return
default:
_, err := fs.Stat(m.uiFs, strings.TrimPrefix(c.Request.URL.Path, "/"))
_, err := fs.Stat(m.uiFs, path)
// Enough for one authentication flow
maxAge := 15 * time.Minute
if os.IsNotExist(err) {
c.Request.URL.Path = "/"
} else if strings.HasPrefix(path, "assets/") {
// assets are named with a hash and can be cached for a long time
maxAge = 30 * 24 * time.Hour
}
c.Writer.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", int(maxAge.Seconds())))
m.uiFileServer.ServeHTTP(c.Writer, c.Request)
c.Abort()
return

View File

@@ -71,14 +71,12 @@ func (docker *DockerService) GetLabels(appDomain string) (config.App, error) {
for _, ctr := range containers {
inspect, err := docker.InspectContainer(ctr.ID)
if err != nil {
log.Warn().Str("id", ctr.ID).Err(err).Msg("Error inspecting container, skipping")
continue
return config.App{}, err
}
labels, err := decoders.DecodeLabels(inspect.Config.Labels)
if err != nil {
log.Warn().Str("id", ctr.ID).Err(err).Msg("Error getting container labels, skipping")
continue
return config.App{}, err
}
for appName, appLabels := range labels.Apps {

View File

@@ -50,7 +50,7 @@ func (broker *OAuthBrokerService) Init() error {
log.Error().Err(err).Msgf("Failed to initialize OAuth service: %T", name)
return err
}
log.Info().Str("service", service.GetName()).Msg("Initialized OAuth service")
log.Info().Str("service", name).Msg("Initialized OAuth service")
}
return nil

View File

@@ -184,7 +184,6 @@ func GetOAuthProvidersConfig(env []string, args []string, appUrl string) (map[st
}
// If we have google/github providers and no redirect URL then set a default
for id := range config.OverrideProviders {
if provider, exists := providers[id]; exists {
if provider.RedirectURL == "" {
@@ -194,6 +193,18 @@ func GetOAuthProvidersConfig(env []string, args []string, appUrl string) (map[st
}
}
// Set names
for id, provider := range providers {
if provider.Name == "" {
if name, ok := config.OverrideProviders[id]; ok {
provider.Name = name
} else {
provider.Name = Capitalize(id)
}
}
providers[id] = provider
}
// Return combined providers
return providers, nil
}

View File

@@ -210,10 +210,12 @@ func TestGetOAuthProvidersConfig(t *testing.T) {
"client1": {
ClientID: "client1-id",
ClientSecret: "client1-secret",
Name: "Client1",
},
"client2": {
ClientID: "client2-id",
ClientSecret: "client2-secret",
Name: "Client2",
},
}
@@ -247,6 +249,7 @@ func TestGetOAuthProvidersConfig(t *testing.T) {
"client1": {
ClientID: "client1-id",
ClientSecret: "file content",
Name: "Client1",
},
}
@@ -262,6 +265,7 @@ func TestGetOAuthProvidersConfig(t *testing.T) {
ClientID: "google-id",
ClientSecret: "google-secret",
RedirectURL: "http://app.url/api/oauth/callback/google",
Name: "Google",
},
}