Separated address and port config
This commit is contained in:
3
.env
3
.env
@@ -1,6 +1,7 @@
|
|||||||
ARTICLE_ROOT=./articles/
|
ARTICLE_ROOT=./articles/
|
||||||
|
|
||||||
SERVER_ADDRESS=localhost:8080
|
SERVER_ADDRESS=localhost
|
||||||
|
SERVER_PORT=8080
|
||||||
|
|
||||||
PREFIX=
|
PREFIX=
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -16,6 +17,7 @@ var (
|
|||||||
ArticleRoot string
|
ArticleRoot string
|
||||||
|
|
||||||
ServerAddress string
|
ServerAddress string
|
||||||
|
ServerPort string
|
||||||
|
|
||||||
Prefix string
|
Prefix string
|
||||||
|
|
||||||
@@ -29,6 +31,7 @@ func init() {
|
|||||||
ArticleRoot = os.Getenv("ARTICLE_ROOT")
|
ArticleRoot = os.Getenv("ARTICLE_ROOT")
|
||||||
|
|
||||||
ServerAddress = os.Getenv("SERVER_ADDRESS")
|
ServerAddress = os.Getenv("SERVER_ADDRESS")
|
||||||
|
ServerPort = os.Getenv("SERVER_PORT")
|
||||||
|
|
||||||
Prefix = path.Join(os.Getenv("PREFIX"))
|
Prefix = path.Join(os.Getenv("PREFIX"))
|
||||||
|
|
||||||
@@ -36,6 +39,6 @@ func init() {
|
|||||||
FrontendDir = os.Getenv("FRONTEND_DIR")
|
FrontendDir = os.Getenv("FRONTEND_DIR")
|
||||||
|
|
||||||
PageBase = pageBase{
|
PageBase = pageBase{
|
||||||
BasePath: "http://" + path.Join(ServerAddress, Prefix) + "/",
|
BasePath: "http://" + path.Join(fmt.Sprintf("%s:%s", ServerAddress, ServerPort), Prefix) + "/",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -33,7 +33,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
database.SetGlobDB(db)
|
database.SetGlobDB(db)
|
||||||
|
|
||||||
if err := http.ListenAndServe(fmt.Sprintf("%s", config.ServerAddress), r); err != nil {
|
if err := http.ListenAndServe(fmt.Sprintf(":%s", config.ServerPort), r); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,9 @@ func setupFrontend(r *mux.Router) {
|
|||||||
|
|
||||||
r.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
r.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if path.Join(config.Prefix)+"/" == r.URL.Path {
|
if path.Join(config.Prefix)+"/" == r.URL.Path {
|
||||||
landingpage.Execute(w, config.PageBase)
|
if err := landingpage.Execute(w, config.PageBase); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
server.Error404(w, r)
|
server.Error404(w, r)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user