mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
suggestions from review
This commit is contained in:
parent
4d760d9a9d
commit
6e797b8115
8 changed files with 66 additions and 29 deletions
17
cli/flags.go
17
cli/flags.go
|
@ -50,6 +50,17 @@ var (
|
||||||
EnvVars: []string{"ENABLE_SYMLINK_SUPPORT"},
|
EnvVars: []string{"ENABLE_SYMLINK_SUPPORT"},
|
||||||
Value: true,
|
Value: true,
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "default-mime-type",
|
||||||
|
Usage: "specifies the default mime type for files that don't have a specific mime type.",
|
||||||
|
EnvVars: []string{"DEFAULT_MIME_TYPE"},
|
||||||
|
Value: "application/octet-stream",
|
||||||
|
},
|
||||||
|
&cli.StringSliceFlag{
|
||||||
|
Name: "forbidden-mime-types",
|
||||||
|
Usage: "specifies the forbidden mime types. Use this flag multiple times for multiple mime types.",
|
||||||
|
EnvVars: []string{"FORBIDDEN_MIME_TYPES"},
|
||||||
|
},
|
||||||
|
|
||||||
// ###########################
|
// ###########################
|
||||||
// ### Page Server Domains ###
|
// ### Page Server Domains ###
|
||||||
|
@ -103,19 +114,19 @@ var (
|
||||||
// Default branches to fetch assets from
|
// Default branches to fetch assets from
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "pages-branch",
|
Name: "pages-branch",
|
||||||
Usage: "define a branch to fetch assets from",
|
Usage: "define a branch to fetch assets from. Use this flag multiple times for multiple branches.",
|
||||||
EnvVars: []string{"PAGES_BRANCHES"},
|
EnvVars: []string{"PAGES_BRANCHES"},
|
||||||
Value: cli.NewStringSlice("pages"),
|
Value: cli.NewStringSlice("pages"),
|
||||||
},
|
},
|
||||||
|
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "allowed-cors-domains",
|
Name: "allowed-cors-domains",
|
||||||
Usage: "specify allowed CORS domains",
|
Usage: "specify allowed CORS domains. Use this flag multiple times for multiple domains.",
|
||||||
EnvVars: []string{"ALLOWED_CORS_DOMAINS"},
|
EnvVars: []string{"ALLOWED_CORS_DOMAINS"},
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "blacklisted-paths",
|
Name: "blacklisted-paths",
|
||||||
Usage: "return an error on these url paths",
|
Usage: "return an error on these url paths.Use this flag multiple times for multiple paths.",
|
||||||
EnvVars: []string{"BLACKLISTED_PATHS"},
|
EnvVars: []string{"BLACKLISTED_PATHS"},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ root = 'codeberg.org'
|
||||||
token = 'XXXXX'
|
token = 'XXXXX'
|
||||||
lfsEnabled = true
|
lfsEnabled = true
|
||||||
followSymlinks = true
|
followSymlinks = true
|
||||||
|
defaultMimeType = "application/wasm"
|
||||||
|
forbiddenMimeTypes = []
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
type = 'sqlite'
|
type = 'sqlite'
|
||||||
|
|
|
@ -15,7 +15,7 @@ type ServerConfig struct {
|
||||||
HttpServerEnabled bool
|
HttpServerEnabled bool
|
||||||
MainDomain string
|
MainDomain string
|
||||||
RawDomain string
|
RawDomain string
|
||||||
DefaultBranches []string
|
PagesBranches []string
|
||||||
AllowedCorsDomains []string
|
AllowedCorsDomains []string
|
||||||
BlacklistedPaths []string
|
BlacklistedPaths []string
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,12 @@ func mergeGiteaConfig(ctx *cli.Context, config *GiteaConfig) {
|
||||||
if ctx.IsSet("enable-symlink-support") {
|
if ctx.IsSet("enable-symlink-support") {
|
||||||
config.FollowSymlinks = ctx.Bool("enable-symlink-support")
|
config.FollowSymlinks = ctx.Bool("enable-symlink-support")
|
||||||
}
|
}
|
||||||
|
if ctx.IsSet("default-mime-type") {
|
||||||
|
config.DefaultMimeType = ctx.String("default-mime-type")
|
||||||
|
}
|
||||||
|
if ctx.IsSet("forbidden-mime-types") {
|
||||||
|
config.ForbiddenMimeTypes = ctx.StringSlice("forbidden-mime-types")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeDatabaseConfig(ctx *cli.Context, config *DatabaseConfig) {
|
func mergeDatabaseConfig(ctx *cli.Context, config *DatabaseConfig) {
|
||||||
|
|
|
@ -96,6 +96,8 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
||||||
Token: "original",
|
Token: "original",
|
||||||
LFSEnabled: false,
|
LFSEnabled: false,
|
||||||
FollowSymlinks: false,
|
FollowSymlinks: false,
|
||||||
|
DefaultMimeType: "original",
|
||||||
|
ForbiddenMimeTypes: []string{"original"},
|
||||||
},
|
},
|
||||||
Database: DatabaseConfig{
|
Database: DatabaseConfig{
|
||||||
Type: "original",
|
Type: "original",
|
||||||
|
@ -132,6 +134,8 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
||||||
Token: "changed",
|
Token: "changed",
|
||||||
LFSEnabled: true,
|
LFSEnabled: true,
|
||||||
FollowSymlinks: true,
|
FollowSymlinks: true,
|
||||||
|
DefaultMimeType: "changed",
|
||||||
|
ForbiddenMimeTypes: []string{"changed"},
|
||||||
},
|
},
|
||||||
Database: DatabaseConfig{
|
Database: DatabaseConfig{
|
||||||
Type: "changed",
|
Type: "changed",
|
||||||
|
@ -169,6 +173,8 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
||||||
"--gitea-api-token", "changed",
|
"--gitea-api-token", "changed",
|
||||||
"--enable-lfs-support",
|
"--enable-lfs-support",
|
||||||
"--enable-symlink-support",
|
"--enable-symlink-support",
|
||||||
|
"--default-mime-type", "changed",
|
||||||
|
"--forbidden-mime-types", "changed",
|
||||||
// Database
|
// Database
|
||||||
"--db-type", "changed",
|
"--db-type", "changed",
|
||||||
"--db-conn", "changed",
|
"--db-conn", "changed",
|
||||||
|
@ -306,6 +312,8 @@ func TestMergeGiteaConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *test
|
||||||
Token: "original",
|
Token: "original",
|
||||||
LFSEnabled: false,
|
LFSEnabled: false,
|
||||||
FollowSymlinks: false,
|
FollowSymlinks: false,
|
||||||
|
DefaultMimeType: "original",
|
||||||
|
ForbiddenMimeTypes: []string{"original"},
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeGiteaConfig(ctx, cfg)
|
mergeGiteaConfig(ctx, cfg)
|
||||||
|
@ -315,6 +323,8 @@ func TestMergeGiteaConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *test
|
||||||
Token: "changed",
|
Token: "changed",
|
||||||
LFSEnabled: true,
|
LFSEnabled: true,
|
||||||
FollowSymlinks: true,
|
FollowSymlinks: true,
|
||||||
|
DefaultMimeType: "changed",
|
||||||
|
ForbiddenMimeTypes: fixArrayFromCtx(ctx, "forbidden-mime-types", []string{"changed"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, expectedConfig, cfg)
|
assert.Equal(t, expectedConfig, cfg)
|
||||||
|
@ -326,6 +336,8 @@ func TestMergeGiteaConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *test
|
||||||
"--gitea-api-token", "changed",
|
"--gitea-api-token", "changed",
|
||||||
"--enable-lfs-support",
|
"--enable-lfs-support",
|
||||||
"--enable-symlink-support",
|
"--enable-symlink-support",
|
||||||
|
"--default-mime-type", "changed",
|
||||||
|
"--forbidden-mime-types", "changed",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -340,6 +352,8 @@ func TestMergeGiteaConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgEx
|
||||||
{args: []string{"--gitea-api-token", "changed"}, callback: func(gc *GiteaConfig) { gc.Token = "changed" }},
|
{args: []string{"--gitea-api-token", "changed"}, callback: func(gc *GiteaConfig) { gc.Token = "changed" }},
|
||||||
{args: []string{"--enable-lfs-support"}, callback: func(gc *GiteaConfig) { gc.LFSEnabled = true }},
|
{args: []string{"--enable-lfs-support"}, callback: func(gc *GiteaConfig) { gc.LFSEnabled = true }},
|
||||||
{args: []string{"--enable-symlink-support"}, callback: func(gc *GiteaConfig) { gc.FollowSymlinks = true }},
|
{args: []string{"--enable-symlink-support"}, callback: func(gc *GiteaConfig) { gc.FollowSymlinks = true }},
|
||||||
|
{args: []string{"--default-mime-type", "changed"}, callback: func(gc *GiteaConfig) { gc.DefaultMimeType = "changed" }},
|
||||||
|
{args: []string{"--forbidden-mime-types", "changed"}, callback: func(gc *GiteaConfig) { gc.ForbiddenMimeTypes = []string{"changed"} }},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pair := range testValuePairs {
|
for _, pair := range testValuePairs {
|
||||||
|
@ -351,6 +365,8 @@ func TestMergeGiteaConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgEx
|
||||||
Token: "original",
|
Token: "original",
|
||||||
LFSEnabled: false,
|
LFSEnabled: false,
|
||||||
FollowSymlinks: false,
|
FollowSymlinks: false,
|
||||||
|
DefaultMimeType: "original",
|
||||||
|
ForbiddenMimeTypes: []string{"original"},
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedConfig := cfg
|
expectedConfig := cfg
|
||||||
|
@ -358,6 +374,8 @@ func TestMergeGiteaConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgEx
|
||||||
|
|
||||||
mergeGiteaConfig(ctx, &cfg)
|
mergeGiteaConfig(ctx, &cfg)
|
||||||
|
|
||||||
|
expectedConfig.ForbiddenMimeTypes = fixArrayFromCtx(ctx, "forbidden-mime-types", expectedConfig.ForbiddenMimeTypes)
|
||||||
|
|
||||||
assert.Equal(t, expectedConfig, cfg)
|
assert.Equal(t, expectedConfig, cfg)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -96,7 +96,7 @@ func Handler(
|
||||||
log.Debug().Msg("subdomain request detected")
|
log.Debug().Msg("subdomain request detected")
|
||||||
handleSubDomain(log, ctx, giteaClient,
|
handleSubDomain(log, ctx, giteaClient,
|
||||||
cfg.MainDomain,
|
cfg.MainDomain,
|
||||||
cfg.DefaultBranches,
|
cfg.PagesBranches,
|
||||||
trimmedHost,
|
trimmedHost,
|
||||||
pathElements,
|
pathElements,
|
||||||
canonicalDomainCache, redirectsCache)
|
canonicalDomainCache, redirectsCache)
|
||||||
|
@ -106,7 +106,7 @@ func Handler(
|
||||||
cfg.MainDomain,
|
cfg.MainDomain,
|
||||||
trimmedHost,
|
trimmedHost,
|
||||||
pathElements,
|
pathElements,
|
||||||
cfg.DefaultBranches[0],
|
cfg.PagesBranches[0],
|
||||||
dnsLookupCache, canonicalDomainCache, redirectsCache)
|
dnsLookupCache, canonicalDomainCache, redirectsCache)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestHandlerPerformance(t *testing.T) {
|
||||||
"/.well-known/acme-challenge/",
|
"/.well-known/acme-challenge/",
|
||||||
},
|
},
|
||||||
AllowedCorsDomains: []string{"raw.codeberg.org", "fonts.codeberg.org", "design.codeberg.org"},
|
AllowedCorsDomains: []string{"raw.codeberg.org", "fonts.codeberg.org", "design.codeberg.org"},
|
||||||
DefaultBranches: []string{"pages"},
|
PagesBranches: []string{"pages"},
|
||||||
}
|
}
|
||||||
testHandler := Handler(serverCfg, giteaClient, cache.NewInMemoryCache(), cache.NewInMemoryCache(), cache.NewInMemoryCache())
|
testHandler := Handler(serverCfg, giteaClient, cache.NewInMemoryCache(), cache.NewInMemoryCache(), cache.NewInMemoryCache())
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ func Serve(ctx *cli.Context) error {
|
||||||
cfg.Server.MainDomain = "." + cfg.Server.MainDomain
|
cfg.Server.MainDomain = "." + cfg.Server.MainDomain
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cfg.Server.DefaultBranches) == 0 {
|
if len(cfg.Server.PagesBranches) == 0 {
|
||||||
return fmt.Errorf("no default branches set (PAGES_BRANCHES)")
|
return fmt.Errorf("no default branches set (PAGES_BRANCHES)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ func Serve(ctx *cli.Context) error {
|
||||||
cfg.Server.MainDomain,
|
cfg.Server.MainDomain,
|
||||||
giteaClient,
|
giteaClient,
|
||||||
acmeClient,
|
acmeClient,
|
||||||
cfg.Server.DefaultBranches[0],
|
cfg.Server.PagesBranches[0],
|
||||||
keyCache, challengeCache, dnsLookupCache, canonicalDomainCache,
|
keyCache, challengeCache, dnsLookupCache, canonicalDomainCache,
|
||||||
certDB,
|
certDB,
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue