repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
52c64d4
parent
ca79cbc
author
Antonio Mika
date
2022-08-31 22:03:52 +0000 UTC
Cleaned up configuration and added debug flag
11 files changed,  +57, -55
M .env.example
+4, -0
 1@@ -30,6 +30,7 @@ LISTS_SUBDOMAINS=1
 2 LISTS_CUSTOMDOMAINS=1
 3 LISTS_PROTOCOL=http
 4 LISTS_ALLOW_REGISTER=1
 5+LISTS_DEBUG=1
 6 
 7 PASTES_V4=
 8 PASTES_V6=
 9@@ -49,6 +50,7 @@ PASTES_SUBDOMAINS=1
10 PASTES_CUSTOMDOMAINS=1
11 PASTES_PROTOCOL=http
12 PASTES_ALLOW_REGISTER=1
13+PASTES_DEBUG=1
14 
15 PROSE_V4=
16 PROSE_V6=
17@@ -68,6 +70,7 @@ PROSE_SUBDOMAINS=1
18 PROSE_CUSTOMDOMAINS=1
19 PROSE_PROTOCOL=http
20 PROSE_ALLOW_REGISTER=1
21+PROSE_DEBUG=1
22 
23 IMGS_V4=
24 IMGS_V6=
25@@ -88,3 +91,4 @@ IMGS_CUSTOMDOMAINS=1
26 IMGS_PROTOCOL=http
27 IMGS_ALLOW_REGISTER=1
28 IMGS_STORAGE_DIR=.storage
29+IMGS_DEBUG=1
M imgs/api.go
+5, -11
 1@@ -15,7 +15,6 @@ import (
 2 	"strings"
 3 	"time"
 4 
 5-	"net/http/pprof"
 6 	_ "net/http/pprof"
 7 
 8 	"git.sr.ht/~erock/pico/db"
 9@@ -780,16 +779,6 @@ func createMainRoutes(staticRoutes []shared.Route) []shared.Route {
10 		shared.NewRoute("GET", "/help", shared.CreatePageHandler("html/help.page.tmpl")),
11 		shared.NewRoute("GET", "/transparency", transparencyHandler),
12 		shared.NewRoute("GET", "/check", shared.CheckHandler),
13-		shared.NewRoute("GET", "/debug/pprof/(.*)", pprof.Index),
14-		shared.NewRoute("GET", "/debug/pprof/cmdline", pprof.Cmdline),
15-		shared.NewRoute("GET", "/debug/pprof/profile", pprof.Profile),
16-		shared.NewRoute("GET", "/debug/pprof/symbol", pprof.Symbol),
17-		shared.NewRoute("GET", "/debug/pprof/trace", pprof.Trace),
18-		shared.NewRoute("POST", "/debug/pprof/(.*)", pprof.Index),
19-		shared.NewRoute("POST", "/debug/pprof/cmdline", pprof.Cmdline),
20-		shared.NewRoute("POST", "/debug/pprof/profile", pprof.Profile),
21-		shared.NewRoute("POST", "/debug/pprof/symbol", pprof.Symbol),
22-		shared.NewRoute("POST", "/debug/pprof/trace", pprof.Trace),
23 	}
24 
25 	routes = append(
26@@ -859,6 +848,11 @@ func StartApiServer() {
27 	}
28 
29 	staticRoutes := createStaticRoutes()
30+
31+	if cfg.Debug {
32+		staticRoutes = shared.CreatePProfRoutes(staticRoutes)
33+	}
34+
35 	mainRoutes := createMainRoutes(staticRoutes)
36 	subdomainRoutes := createSubdomainRoutes(staticRoutes)
37 
M imgs/config.go
+4, -11
 1@@ -29,6 +29,7 @@ func (i *ImgsLinkify) Create(fname string) string {
 2 }
 3 
 4 func NewConfigSite() *shared.ConfigSite {
 5+	debug := shared.GetEnv("IMGS_DEBUG", "0")
 6 	domain := shared.GetEnv("IMGS_DOMAIN", "prose.sh")
 7 	email := shared.GetEnv("IMGS_EMAIL", "hello@prose.sh")
 8 	subdomains := shared.GetEnv("IMGS_SUBDOMAINS", "0")
 9@@ -41,15 +42,6 @@ func NewConfigSite() *shared.ConfigSite {
10 	minioUser := shared.GetEnv("MINIO_ROOT_USER", "")
11 	minioPass := shared.GetEnv("MINIO_ROOT_PASSWORD", "")
12 	dbURL := shared.GetEnv("DATABASE_URL", "")
13-	subdomainsEnabled := false
14-	if subdomains == "1" {
15-		subdomainsEnabled = true
16-	}
17-
18-	customdomainsEnabled := false
19-	if customdomains == "1" {
20-		customdomainsEnabled = true
21-	}
22 
23 	intro := "To get started, enter a username.\n"
24 	intro += "Then create a folder locally (e.g. ~/imgs).\n"
25@@ -57,8 +49,9 @@ func NewConfigSite() *shared.ConfigSite {
26 	intro += fmt.Sprintf("scp ~/imgs/*.jpg %s:/", domain)
27 
28 	cfg := shared.ConfigSite{
29-		SubdomainsEnabled:    subdomainsEnabled,
30-		CustomdomainsEnabled: customdomainsEnabled,
31+		Debug:                debug == "1",
32+		SubdomainsEnabled:    subdomains == "1",
33+		CustomdomainsEnabled: customdomains == "1",
34 		ConfigCms: config.ConfigCms{
35 			Domain:        domain,
36 			Email:         email,
M lists/api.go
+5, -0
 1@@ -752,6 +752,11 @@ func StartApiServer() {
 2 	}
 3 
 4 	staticRoutes := createStaticRoutes()
 5+
 6+	if cfg.Debug {
 7+		staticRoutes = shared.CreatePProfRoutes(staticRoutes)
 8+	}
 9+
10 	mainRoutes := createMainRoutes(staticRoutes)
11 	subdomainRoutes := createSubdomainRoutes(staticRoutes)
12 
M lists/config.go
+4, -11
 1@@ -8,6 +8,7 @@ import (
 2 )
 3 
 4 func NewConfigSite() *shared.ConfigSite {
 5+	debug := shared.GetEnv("LISTS_DEBUG", "0")
 6 	domain := shared.GetEnv("LISTS_DOMAIN", "lists.sh")
 7 	email := shared.GetEnv("LISTS_EMAIL", "support@lists.sh")
 8 	subdomains := shared.GetEnv("LISTS_SUBDOMAINS", "0")
 9@@ -20,15 +21,6 @@ func NewConfigSite() *shared.ConfigSite {
10 	minioUser := shared.GetEnv("MINIO_ROOT_USER", "")
11 	minioPass := shared.GetEnv("MINIO_ROOT_PASSWORD", "")
12 	dbURL := shared.GetEnv("DATABASE_URL", "")
13-	subdomainsEnabled := false
14-	if subdomains == "1" {
15-		subdomainsEnabled = true
16-	}
17-
18-	customdomainsEnabled := false
19-	if customdomains == "1" {
20-		customdomainsEnabled = true
21-	}
22 
23 	intro := "To get started, enter a username.\n"
24 	intro += "Then create a folder locally (e.g. ~/blog).\n"
25@@ -37,8 +29,9 @@ func NewConfigSite() *shared.ConfigSite {
26 	intro += fmt.Sprintf("scp ~/blog/*.txt %s:/\n\n", domain)
27 
28 	return &shared.ConfigSite{
29-		SubdomainsEnabled:    subdomainsEnabled,
30-		CustomdomainsEnabled: customdomainsEnabled,
31+		Debug:                debug == "1",
32+		SubdomainsEnabled:    subdomains == "1",
33+		CustomdomainsEnabled: customdomains == "1",
34 		ConfigCms: config.ConfigCms{
35 			Domain:        domain,
36 			Email:         email,
M pastes/api.go
+5, -0
 1@@ -407,6 +407,11 @@ func StartApiServer() {
 2 	go CronDeleteExpiredPosts(cfg, db)
 3 
 4 	staticRoutes := createStaticRoutes()
 5+
 6+	if cfg.Debug {
 7+		staticRoutes = shared.CreatePProfRoutes(staticRoutes)
 8+	}
 9+
10 	mainRoutes := createMainRoutes(staticRoutes)
11 	subdomainRoutes := createSubdomainRoutes(staticRoutes)
12 
M pastes/config.go
+4, -11
 1@@ -8,6 +8,7 @@ import (
 2 )
 3 
 4 func NewConfigSite() *shared.ConfigSite {
 5+	debug := shared.GetEnv("PASTES_DEBUG", "0")
 6 	domain := shared.GetEnv("PASTES_DOMAIN", "pastes.sh")
 7 	email := shared.GetEnv("PASTES_EMAIL", "hello@pastes.sh")
 8 	subdomains := shared.GetEnv("PASTES_SUBDOMAINS", "0")
 9@@ -20,15 +21,6 @@ func NewConfigSite() *shared.ConfigSite {
10 	minioURL := shared.GetEnv("MINIO_URL", "")
11 	minioUser := shared.GetEnv("MINIO_ROOT_USER", "")
12 	minioPass := shared.GetEnv("MINIO_ROOT_PASSWORD", "")
13-	subdomainsEnabled := false
14-	if subdomains == "1" {
15-		subdomainsEnabled = true
16-	}
17-
18-	customdomainsEnabled := false
19-	if customdomains == "1" {
20-		customdomainsEnabled = true
21-	}
22 
23 	intro := "To get started, enter a username.\n"
24 	intro += "Then create a folder locally (e.g. ~/pastes).\n"
25@@ -37,8 +29,9 @@ func NewConfigSite() *shared.ConfigSite {
26 	intro += fmt.Sprintf("scp ~/pastes/* %s:/", domain)
27 
28 	return &shared.ConfigSite{
29-		SubdomainsEnabled:    subdomainsEnabled,
30-		CustomdomainsEnabled: customdomainsEnabled,
31+		Debug:                debug == "1",
32+		SubdomainsEnabled:    subdomains == "1",
33+		CustomdomainsEnabled: customdomains == "1",
34 		ConfigCms: config.ConfigCms{
35 			Domain:        domain,
36 			Port:          port,
M prose/api.go
+5, -0
 1@@ -907,6 +907,11 @@ func StartApiServer() {
 2 	}
 3 
 4 	staticRoutes := createStaticRoutes()
 5+
 6+	if cfg.Debug {
 7+		staticRoutes = shared.CreatePProfRoutes(staticRoutes)
 8+	}
 9+
10 	mainRoutes := createMainRoutes(staticRoutes)
11 	subdomainRoutes := createSubdomainRoutes(staticRoutes)
12 
M prose/config.go
+4, -11
 1@@ -8,6 +8,7 @@ import (
 2 )
 3 
 4 func NewConfigSite() *shared.ConfigSite {
 5+	debug := shared.GetEnv("PROSE_DEBUG", "0")
 6 	domain := shared.GetEnv("PROSE_DOMAIN", "prose.sh")
 7 	email := shared.GetEnv("PROSE_EMAIL", "hello@prose.sh")
 8 	subdomains := shared.GetEnv("PROSE_SUBDOMAINS", "0")
 9@@ -20,15 +21,6 @@ func NewConfigSite() *shared.ConfigSite {
10 	minioUser := shared.GetEnv("MINIO_ROOT_USER", "")
11 	minioPass := shared.GetEnv("MINIO_ROOT_PASSWORD", "")
12 	dbURL := shared.GetEnv("DATABASE_URL", "")
13-	subdomainsEnabled := false
14-	if subdomains == "1" {
15-		subdomainsEnabled = true
16-	}
17-
18-	customdomainsEnabled := false
19-	if customdomains == "1" {
20-		customdomainsEnabled = true
21-	}
22 
23 	intro := "To get started, enter a username.\n"
24 	intro += "Then create a folder locally (e.g. ~/blog).\n"
25@@ -37,8 +29,9 @@ func NewConfigSite() *shared.ConfigSite {
26 	intro += fmt.Sprintf("scp ~/blog/*.md %s:/", domain)
27 
28 	return &shared.ConfigSite{
29-		SubdomainsEnabled:    subdomainsEnabled,
30-		CustomdomainsEnabled: customdomainsEnabled,
31+		Debug:                debug == "1",
32+		SubdomainsEnabled:    subdomains == "1",
33+		CustomdomainsEnabled: customdomains == "1",
34 		ConfigCms: config.ConfigCms{
35 			Domain:        domain,
36 			Email:         email,
M shared/config.go
+1, -0
1@@ -25,6 +25,7 @@ type PageData struct {
2 type ConfigSite struct {
3 	config.ConfigCms
4 	config.ConfigURL
5+	Debug                bool
6 	SubdomainsEnabled    bool
7 	CustomdomainsEnabled bool
8 }
M shared/router.go
+16, -0
 1@@ -5,6 +5,7 @@ import (
 2 	"fmt"
 3 	"net"
 4 	"net/http"
 5+	"net/http/pprof"
 6 	"regexp"
 7 	"strings"
 8 
 9@@ -27,6 +28,21 @@ func NewRoute(method, pattern string, handler http.HandlerFunc) Route {
10 	}
11 }
12 
13+func CreatePProfRoutes(routes []Route) []Route {
14+	return append(routes,
15+		NewRoute("GET", "/debug/pprof/cmdline", pprof.Cmdline),
16+		NewRoute("GET", "/debug/pprof/profile", pprof.Profile),
17+		NewRoute("GET", "/debug/pprof/symbol", pprof.Symbol),
18+		NewRoute("GET", "/debug/pprof/trace", pprof.Trace),
19+		NewRoute("GET", "/debug/pprof/(.*)", pprof.Index),
20+		NewRoute("POST", "/debug/pprof/cmdline", pprof.Cmdline),
21+		NewRoute("POST", "/debug/pprof/profile", pprof.Profile),
22+		NewRoute("POST", "/debug/pprof/symbol", pprof.Symbol),
23+		NewRoute("POST", "/debug/pprof/trace", pprof.Trace),
24+		NewRoute("POST", "/debug/pprof/(.*)", pprof.Index),
25+	)
26+}
27+
28 type ServeFn func(http.ResponseWriter, *http.Request)
29 
30 func CreateServe(routes []Route, subdomainRoutes []Route, cfg *ConfigSite, dbpool db.DB, st storage.ObjectStorage, logger *zap.SugaredLogger) ServeFn {