added root url

This commit is contained in:
4rkal 2024-09-12 21:59:49 +03:00
parent b12d275fbf
commit 620306b6ae
4 changed files with 19 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"math/rand"
"net/http"
@ -28,6 +29,14 @@ type StatsFormData struct {
var linkMap = map[string]*models.Link{}
var baseurl *string
func init() {
baseurl = flag.String("url", "127.0.0.1:8080", "The url (domain) that the server is running on")
flag.Parse()
}
func main() {
e := echo.New()
@ -86,7 +95,7 @@ func SubmitHandler(c echo.Context) error {
linkMap[id] = &models.Link{Id: id, Url: data.Url}
return views.Submission(id).Render(c.Request().Context(), c.Response())
return views.Submission(id, *baseurl).Render(c.Request().Context(), c.Response())
}
func StatsHandler(c echo.Context) error {

View File

@ -6,4 +6,5 @@ services:
dockerfile: Dockerfile
ports:
- "8080:8080"
restart: unless-stopped
restart: unless-stopped
command: ["/shortr", "--url", "app.4rkal.com"]

View File

@ -1,9 +1,9 @@
package views
templ Submission(url string){
templ Submission(url, baseurl string){
@Base() {
<h1>Your url is: {url}</h1>
<h1>Your url is: <code>{baseurl + "/" + url}</code></h1>
<form action="/stats" method="post">
<input type="hidden" id="id" name="id" value={url}>

View File

@ -8,7 +8,7 @@ package views
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
func Submission(url string) templ.Component {
func Submission(url, baseurl string) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@ -41,20 +41,20 @@ func Submission(url string) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>Your url is: ")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>Your url is: <code>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(url)
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(baseurl + "/" + url)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/submit.templ`, Line: 6, Col: 25}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/submit.templ`, Line: 6, Col: 47}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h1><form action=\"/stats\" method=\"post\"><input type=\"hidden\" id=\"id\" name=\"id\" value=\"")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</code></h1><form action=\"/stats\" method=\"post\"><input type=\"hidden\" id=\"id\" name=\"id\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}