Antonio Mika
·
2026-10-10
1package pipe
2
3import (
4 "html/template"
5 "log/slog"
6 "strings"
7
8 "github.com/picosh/pico/pkg/shared"
9 "github.com/picosh/pico/pkg/shared/router"
10)
11
12// staticDir holds pipe's templates and public files.
13const staticDir = "pkg/apps/pipe"
14
15type Config struct {
16 Debug bool
17 Domain string
18 Port string
19 // PortOverride is the ssh port users connect to, when it isn't 22.
20 PortOverride string
21 Protocol string
22 DbURL string
23 Space string
24 Logger *slog.Logger
25}
26
27func NewConfig(service string) *Config {
28 domain := shared.GetEnv("PIPE_DOMAIN", "pipe.pico.sh")
29 port := shared.GetEnv("PIPE_WEB_PORT", "3000")
30 dbURL := shared.GetEnv("DATABASE_URL", "")
31 protocol := shared.GetEnv("PIPE_PROTOCOL", "https")
32 withPipe := strings.ToLower(shared.GetEnv("PICO_PIPE_ENABLED", "true")) == "true"
33
34 return &Config{
35 Domain: domain,
36 Port: port,
37 Protocol: protocol,
38 DbURL: dbURL,
39 Logger: shared.CreateLogger(service, withPipe),
40 Space: "pipe",
41 }
42}
43
44func (c *Config) Static() router.Static {
45 return router.Static{
46 Dir: staticDir,
47 Logger: c.Logger,
48 Site: shared.SitePageData{
49 Domain: template.URL(c.Domain),
50 HomeURL: template.URL("//" + c.Domain),
51 },
52 }
53}