Added config setting to disable site
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"quay/internal/config"
|
"quay/internal/config"
|
||||||
@@ -16,6 +15,10 @@ func NewStaticHandler(storagePath string, siteMap map[string]config.SiteConfig)
|
|||||||
return c.Status(fiber.StatusNotFound).SendString("Site not found")
|
return c.Status(fiber.StatusNotFound).SendString("Site not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !site.Enabled {
|
||||||
|
return c.Status(fiber.StatusServiceUnavailable).SendString("Site is currently unavailable")
|
||||||
|
}
|
||||||
|
|
||||||
urlPath := filepath.Clean(c.Path())
|
urlPath := filepath.Clean(c.Path())
|
||||||
|
|
||||||
for _, rule := range site.ForwardRules {
|
for _, rule := range site.ForwardRules {
|
||||||
@@ -23,7 +26,6 @@ func NewStaticHandler(storagePath string, siteMap map[string]config.SiteConfig)
|
|||||||
match := rule.Compiled.FindStringSubmatchIndex(urlPath)
|
match := rule.Compiled.FindStringSubmatchIndex(urlPath)
|
||||||
if match != nil {
|
if match != nil {
|
||||||
dest := rule.Compiled.ExpandString([]byte{}, rule.Destination, urlPath, match)
|
dest := rule.Compiled.ExpandString([]byte{}, rule.Destination, urlPath, match)
|
||||||
log.Printf("Forwarding %s to %s based on regex rule", urlPath, dest)
|
|
||||||
return c.Redirect().Status(rule.StatusCode).To(string(dest))
|
return c.Redirect().Status(rule.StatusCode).To(string(dest))
|
||||||
}
|
}
|
||||||
} else if rule.Source == urlPath {
|
} else if rule.Source == urlPath {
|
||||||
|
|||||||
+5
-2
@@ -8,6 +8,7 @@ sites:
|
|||||||
branch: gh-pages
|
branch: gh-pages
|
||||||
domain: docs.my-lib.com
|
domain: docs.my-lib.com
|
||||||
deploy_token: "${MY_LIB_DEPLOY_TOKEN}"
|
deploy_token: "${MY_LIB_DEPLOY_TOKEN}"
|
||||||
|
enabled: true
|
||||||
forward_rules:
|
forward_rules:
|
||||||
- source: /npm
|
- source: /npm
|
||||||
destination: https://www.npmjs.com/package/my-lib
|
destination: https://www.npmjs.com/package/my-lib
|
||||||
@@ -17,7 +18,7 @@ sites:
|
|||||||
destination: https://v$1.docs.my-lib.com/
|
destination: https://v$1.docs.my-lib.com/
|
||||||
status_code: 301
|
status_code: 301
|
||||||
regex: true
|
regex: true
|
||||||
|
|
||||||
- source: ^/blog/(?P<slug>[^/]+)$
|
- source: ^/blog/(?P<slug>[^/]+)$
|
||||||
destination: /posts/${slug}
|
destination: /posts/${slug}
|
||||||
status_code: 302
|
status_code: 302
|
||||||
@@ -29,9 +30,11 @@ sites:
|
|||||||
domain: yourname.com
|
domain: yourname.com
|
||||||
spa: true
|
spa: true
|
||||||
deploy_token: "${PORTFOLIO_DEPLOY_TOKEN}"
|
deploy_token: "${PORTFOLIO_DEPLOY_TOKEN}"
|
||||||
|
enabled: true
|
||||||
|
|
||||||
- repo: other-docs
|
- repo: other-docs
|
||||||
owner: yourname
|
owner: yourname
|
||||||
branch: gh-pages
|
branch: gh-pages
|
||||||
domain: other-docs.yourdomain.com
|
domain: other-docs.yourdomain.com
|
||||||
deploy_token: "${OTHER_DOCS_DEPLOY_TOKEN}"
|
deploy_token: "${OTHER_DOCS_DEPLOY_TOKEN}"
|
||||||
|
enabled: true
|
||||||
@@ -23,6 +23,7 @@ type SiteConfig struct {
|
|||||||
Owner string `yaml:"owner"`
|
Owner string `yaml:"owner"`
|
||||||
Branch string `yaml:"branch"`
|
Branch string `yaml:"branch"`
|
||||||
Domain string `yaml:"domain"`
|
Domain string `yaml:"domain"`
|
||||||
|
Enabled bool `yaml:"enabled"`
|
||||||
SPA bool `yaml:"spa"`
|
SPA bool `yaml:"spa"`
|
||||||
NotFoundFile string `yaml:"not_found_file"`
|
NotFoundFile string `yaml:"not_found_file"`
|
||||||
DeployToken string `yaml:"deploy_token"`
|
DeployToken string `yaml:"deploy_token"`
|
||||||
|
|||||||
Reference in New Issue
Block a user