Fixed base path (again)
This commit is contained in:
1
.env
1
.env
@@ -2,6 +2,7 @@ ARTICLE_ROOT=./articles/
|
||||
|
||||
SERVER_ADDRESS=localhost
|
||||
SERVER_PORT=8080
|
||||
PROTOCOL=http
|
||||
|
||||
PREFIX=
|
||||
|
||||
|
||||
@@ -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) + "/"
|
||||
}
|
||||
|
||||
6
main.go
6
main.go
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user