Fixed base path
This commit is contained in:
@@ -7,12 +7,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pageBase struct {
|
|
||||||
BasePath string
|
|
||||||
}
|
|
||||||
|
|
||||||
var PageBase pageBase
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ArticleRoot string
|
ArticleRoot string
|
||||||
|
|
||||||
@@ -23,6 +17,10 @@ var (
|
|||||||
|
|
||||||
DatabaseFile string
|
DatabaseFile string
|
||||||
FrontendDir string
|
FrontendDir string
|
||||||
|
|
||||||
|
// not specified in config
|
||||||
|
|
||||||
|
BasePath string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -38,7 +36,5 @@ func init() {
|
|||||||
DatabaseFile = os.Getenv("DATABASE_FILE")
|
DatabaseFile = os.Getenv("DATABASE_FILE")
|
||||||
FrontendDir = os.Getenv("FRONTEND_DIR")
|
FrontendDir = os.Getenv("FRONTEND_DIR")
|
||||||
|
|
||||||
PageBase = pageBase{
|
BasePath = path.Join(fmt.Sprintf("%s:%s", ServerAddress, ServerPort), Prefix) + "/"
|
||||||
BasePath: "http://" + path.Join(fmt.Sprintf("%s:%s", ServerAddress, ServerPort), Prefix) + "/",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
8
main.go
8
main.go
@@ -67,7 +67,13 @@ func setupFrontend(r *mux.Router) {
|
|||||||
|
|
||||||
landingpage := template.Must(template.ParseFiles(filepath.Join(config.FrontendDir, "html", "landingpage.gohtml")))
|
landingpage := template.Must(template.ParseFiles(filepath.Join(config.FrontendDir, "html", "landingpage.gohtml")))
|
||||||
r.Path("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
r.Path("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
landingpage.Execute(w, config.PageBase)
|
basePath := r.URL.Scheme + "://" + config.BasePath
|
||||||
|
if r.URL.Scheme == "" {
|
||||||
|
basePath = "http" + basePath
|
||||||
|
}
|
||||||
|
landingpage.Execute(w, struct {
|
||||||
|
BasePath string
|
||||||
|
}{BasePath: basePath})
|
||||||
})
|
})
|
||||||
|
|
||||||
r.NotFoundHandler = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
r.NotFoundHandler = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -38,9 +38,14 @@ 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("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)
|
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{
|
ta := tmplArticle{
|
||||||
Title: article.Title,
|
Title: article.Title,
|
||||||
BasePath: config.PageBase.BasePath,
|
BasePath: basePath,
|
||||||
Summary: article.Summary,
|
Summary: article.Summary,
|
||||||
Image: article.Image,
|
Image: article.Image,
|
||||||
Authors: authors,
|
Authors: authors,
|
||||||
|
|||||||
Reference in New Issue
Block a user