Mac Chaffee
·
17 Dec 24
config.go
1package pgs
2
3import (
4 "fmt"
5 "time"
6
7 "github.com/picosh/pico/shared"
8 "github.com/picosh/utils"
9)
10
11var maxSize = uint64(25 * utils.MB)
12var maxAssetSize = int64(10 * utils.MB)
13
14// Needs to be small for caching files like _headers and _redirects.
15var maxSpecialFileSize = int64(5 * utils.KB)
16
17func NewConfigSite() *shared.ConfigSite {
18 domain := utils.GetEnv("PGS_DOMAIN", "pgs.sh")
19 port := utils.GetEnv("PGS_WEB_PORT", "3000")
20 protocol := utils.GetEnv("PGS_PROTOCOL", "https")
21 storageDir := utils.GetEnv("PGS_STORAGE_DIR", ".storage")
22 cacheTTL, err := time.ParseDuration(utils.GetEnv("PGS_CACHE_TTL", ""))
23 if err != nil {
24 cacheTTL = 600 * time.Second
25 }
26 cacheControl := utils.GetEnv(
27 "PGS_CACHE_CONTROL",
28 fmt.Sprintf("max-age=%d", int(cacheTTL.Seconds())))
29 minioURL := utils.GetEnv("MINIO_URL", "")
30 minioUser := utils.GetEnv("MINIO_ROOT_USER", "")
31 minioPass := utils.GetEnv("MINIO_ROOT_PASSWORD", "")
32 dbURL := utils.GetEnv("DATABASE_URL", "")
33
34 cfg := shared.ConfigSite{
35 Domain: domain,
36 Port: port,
37 Protocol: protocol,
38 DbURL: dbURL,
39 StorageDir: storageDir,
40 CacheTTL: cacheTTL,
41 CacheControl: cacheControl,
42 MinioURL: minioURL,
43 MinioUser: minioUser,
44 MinioPass: minioPass,
45 Space: "pgs",
46 MaxSize: maxSize,
47 MaxAssetSize: maxAssetSize,
48 MaxSpecialFileSize: maxSpecialFileSize,
49 Logger: shared.CreateLogger("pgs"),
50 }
51
52 return &cfg
53}