From 29896be872d263a5313e8f628d94f6ead3c4d004 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 7 Dec 2021 17:24:24 +0100 Subject: [PATCH] Fixes --- docker-compose.yml | 4 --- main.go | 16 ++++++---- views/home.html | 80 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 71 insertions(+), 29 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f663b87..81295f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,10 +13,6 @@ services: command: redis-server --appendonly yes volumes: - db:/data - ports: - - "6379:6379" - environment: - - REDIS_PASSWORD=abc123 restart: always volumes: diff --git a/main.go b/main.go index ea3afa4..8f92669 100644 --- a/main.go +++ b/main.go @@ -21,8 +21,8 @@ func main() { }) client := redis.NewClient(&redis.Options{ - Addr: "db:6379", - Password: "abc123", + Addr: "redis:6379", + Password: "", DB: 0, }) @@ -37,7 +37,7 @@ func main() { }) type EUrl struct { - URL string `json:"surl" xml:"surl" form:"surl"` + URL string `form:"surl"` } app.Get("/:id", func(c *fiber.Ctx) error { @@ -62,8 +62,8 @@ func main() { return err } - if !regexp.MustCompile(`^(http|https)://`).MatchString(u.URL) { - c.Status(http.StatusBadRequest).SendString("Invalid URL") + if !regexp.MustCompile(`^(http|https|mailto|ts3server)://`).MatchString(u.URL) { + return c.Status(http.StatusBadRequest).SendString("Invalid URL") } id, err := gonanoid.New(8) @@ -78,7 +78,11 @@ func main() { c.SendString(err.Error()) } - return c.SendString("https://" + c.Hostname() + "/" + id) + fURL := c.Protocol() + "://" + c.Hostname() + "/" + id + + return c.Render("home", fiber.Map{ + "URL": fURL, + }) }) log.Fatal(app.Listen(":3000")) diff --git a/views/home.html b/views/home.html index 99ef535..60c809b 100644 --- a/views/home.html +++ b/views/home.html @@ -6,32 +6,74 @@ - + + + +

-
-
-

goshortly

-

An dead simple & fast URL Shortner

-

All shortend URLs will be available for 30days

-
-
-
-
- -
- -
-
-
+
+

goshortly

+

An dead simple & fast URL Shortner.
+ All shortend URLs will be available for 30days! +

+
+
+
+ +
+
+ +
+
+
-
- + + + \ No newline at end of file