This commit is contained in:
Phil 2021-12-07 17:24:24 +01:00
parent 10746d5dba
commit 29896be872
3 changed files with 71 additions and 29 deletions

View file

@ -13,10 +13,6 @@ services:
command: redis-server --appendonly yes
volumes:
- db:/data
ports:
- "6379:6379"
environment:
- REDIS_PASSWORD=abc123
restart: always
volumes:

16
main.go
View file

@ -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"))

View file

@ -6,32 +6,74 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://bootswatch.com/5/darkly/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet">
<link href="https://bootswatch.com/4/darkly/bootstrap.min.css" rel="stylesheet">
</head>
<style>
html {
height: 100%;
}
body {
height: 100%;
display: grid;
grid-template-rows: auto 1fr auto;
}
footer {
background-color: #303030;
padding: 10px;
}
</style>
<body>
<br><br>
<div class="container">
<div class="mt-2 mb-4 bg-secondary rounded-3">
<div class="container-fluid py-5">
<h1 class="display-5 fw-bold">goshortly</h1>
<p class="col-md-8 fs-4">An dead simple & fast URL Shortner</p>
<p class="col-md-8 fs-4">All shortend URLs will be available for 30days</p>
<hr>
<form method="post" action="#">
<fieldset>
<div class="container">
<input type="text" class="form-control" id="surl" name="surl" placeholder="https://google.de" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</fieldset>
</form>
</div>
<div class="jumbotron">
<h1>goshortly</h1>
<p>An dead simple & fast URL Shortner. <br>
All shortend URLs will be available for 30days!
</p>
<hr>
<form method="post" action="#">
<fieldset>
<input type="text" class="form-control" id="surl" name="surl" placeholder="https://google.de"
required>
<br>
<center>
<button type="submit" class="btn btn-primary btn-lg">Submit</button>
</center>
</fieldset>
</form>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous">
<!-- URL PASS CHECK -->
{{ if .URL }}
<div style="padding-right: 20px;" class="alert alert-dismissible alert-success">
<input id="foo" class="form-control" value="{{ .URL }}" readonly>
<br>
<center>
<button class="btn-copy btn btn-success" data-clipboard-target="#foo">
Copy to clipboard
</button>
</center>
</div>
{{ end }}
</div>
<footer>
<center>
Made with <a href="https://git.ucode.space/Phil/goshorly"><i class="fas fa-code-branch"></i>
Phil/goshortly</a>
</center>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>
<script>
new ClipboardJS('body > div > div.alert.alert-dismissible.alert-success > center > button');
</script>
</body>
</html>