diff --git a/docker-compose-proxy.yml b/docker-compose-proxy.yml index 0157873..b416a0c 100644 --- a/docker-compose-proxy.yml +++ b/docker-compose-proxy.yml @@ -1,8 +1,13 @@ version: "3" services: web: - # build: . # Only if you want to Build the image on your own Server! + # build: . # Only if you want to Build the image on your own Server! image: registry.ucode.space/phil/goshorly:latest + environment: + - HOST=example.org # Domain or IP-Adress + - HTTPS=true # If you want to use HTTPS + - PROXY=true # If you want to use a Reverse Proxy + - PORT=3000 # The Port you want to use depends_on: - redis restart: always @@ -17,7 +22,7 @@ services: caddy: image: caddy:2 restart: always - command: caddy reverse-proxy --from https://my-domain.com:443 --to http://web:3000 + command: caddy reverse-proxy --from https://example.org:443 --to http://web:3000 ports: - 80:80 - 443:443 diff --git a/docker-compose.yml b/docker-compose.yml index ae4a08b..d17cea2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,13 @@ version: "3" services: web: - # build: . # Only if you want to Build the image on your own Server! + # build: . # Only if you want to Build the image on your own Server! image: registry.ucode.space/phil/goshorly:latest + environment: + - HOST=your_domain_or_ip # Domain or IP-Adress + - HTTPS=false # If you want to use HTTPS + - PROXY=false # If you want to use a Reverse Proxy + - PORT=3000 # The Port you want to use ports: - "3000:3000" depends_on: diff --git a/main.go b/main.go index 1e391fc..9765a94 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "regexp" "time" + "git.ucode.space/Phil/goshorly/utils" "github.com/go-redis/redis" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/limiter" @@ -19,6 +20,8 @@ var viewsfs embed.FS func main() { + utils.Init_ENV() + engine := html.NewFileSystem(http.FS(viewsfs), ".html") app := fiber.New(fiber.Config{ @@ -51,7 +54,7 @@ func main() { val, err := client.Get(c.Params("id")).Result() if err != nil { return c.Render("views/404", fiber.Map{ - "BASEURL": c.Protocol() + "://" + c.Hostname(), + "BASEURL": utils.URL, }) } return c.Redirect(val) @@ -97,12 +100,12 @@ func main() { }) } - fURL := c.Protocol() + "://" + c.Hostname() + "/" + id + fURL := utils.URL + id return c.Render("views/home", fiber.Map{ "URL": fURL, }) }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":" + utils.PORT)) } diff --git a/utils/env.go b/utils/env.go new file mode 100644 index 0000000..7dc07a6 --- /dev/null +++ b/utils/env.go @@ -0,0 +1,56 @@ +package utils + +import ( + "fmt" + "log" + "os" +) + +var HOST string +var HTTPS string +var PROXY bool +var PORT string + +var URL string + +func Init_ENV() { + UHOST, err := os.LookupEnv("HOST") + if !err { + log.Fatal("HOST enviroment variable not found, please set it!") + } + HOST = UHOST + + UHTTPS, _ := os.LookupEnv("HTTPS") + if UHTTPS != "true" { + HTTPS = "http" + } else { + HTTPS = "https" + } + + UPROXY, _ := os.LookupEnv("PROXY") + if UPROXY != "true" { + PROXY = false + } else { + PROXY = true + } + + UPORT, err := os.LookupEnv("PORT") + if !err { + PORT = "3000" + } else { + PORT = UPORT + } + + create_string() + +} + +func create_string() { + if !PROXY { + URL = HTTPS + "://" + HOST + ":" + PORT + "/" + } else { + URL = HTTPS + "://" + HOST + "/" + } + + fmt.Println(URL) +}