Fixed base path (again)

This commit is contained in:
2022-02-02 10:10:47 +01:00
parent cac2111296
commit cfe33f517b
4 changed files with 6 additions and 12 deletions

1
.env
View File

@@ -2,6 +2,7 @@ ARTICLE_ROOT=./articles/
SERVER_ADDRESS=localhost
SERVER_PORT=8080
PROTOCOL=http
PREFIX=

View File

@@ -12,6 +12,7 @@ var (
ServerAddress string
ServerPort string
Protocol string
Prefix string
@@ -30,11 +31,12 @@ func init() {
ServerAddress = os.Getenv("SERVER_ADDRESS")
ServerPort = os.Getenv("SERVER_PORT")
Protocol = os.Getenv("PROTOCOL")
Prefix = path.Join(os.Getenv("PREFIX"))
DatabaseFile = os.Getenv("DATABASE_FILE")
FrontendDir = os.Getenv("FRONTEND_DIR")
BasePath = path.Join(fmt.Sprintf("%s:%s", ServerAddress, ServerPort), Prefix) + "/"
BasePath = Protocol + path.Join(fmt.Sprintf("%s:%s", ServerAddress, ServerPort), Prefix) + "/"
}

View File

@@ -67,13 +67,9 @@ func setupFrontend(r *mux.Router) {
landingpage := template.Must(template.ParseFiles(filepath.Join(config.FrontendDir, "html", "landingpage.gohtml")))
r.Path("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
basePath := r.URL.Scheme + "://" + config.BasePath
if r.URL.Scheme == "" {
basePath = "http" + basePath
}
landingpage.Execute(w, struct {
BasePath string
}{BasePath: basePath})
}{BasePath: config.BasePath})
})
r.NotFoundHandler = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

View File

@@ -38,14 +38,9 @@ func Article(w http.ResponseWriter, r *http.Request) {
database.GetDB().Table("author").Select("id").Where("id IN (?)", database.GetDB().Table("article_author").Select("author_id").Where("article_id = ?", article.Id)).Find(&authors)
database.GetDB().Table("article_tag").Where("article_id = ?", article.Id).Find(&tags)
basePath := r.URL.Scheme + "://" + config.BasePath
if r.URL.Scheme == "" {
basePath = "http" + basePath
}
ta := tmplArticle{
Title: article.Title,
BasePath: basePath,
BasePath: config.Protocol,
Summary: article.Summary,
Image: article.Image,
Authors: authors,