Added environment vars for easy setup
This commit is contained in:
parent
133ae32b3b
commit
38226336e0
4 changed files with 75 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
9
main.go
9
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))
|
||||
}
|
||||
|
|
56
utils/env.go
Normal file
56
utils/env.go
Normal file
|
@ -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)
|
||||
}
|
Loading…
Reference in a new issue