v0.1.5 Fix bug with host routing

This commit is contained in:
Yann Stepienik 2023-04-01 17:49:54 +01:00
parent 50498b406c
commit 543204a87c
2 changed files with 5 additions and 12 deletions

View file

@ -1,6 +1,6 @@
{
"name": "cosmos-server",
"version": "0.1.4",
"version": "0.1.5",
"description": "",
"main": "test-server.js",
"bugs": {

View file

@ -183,17 +183,6 @@ func StartServer() {
router.Use(middleware.Logger)
router.Use(utils.SetSecurityHeaders)
router.Methods("GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"OPTIONS",
"HEAD",
).Host(config.Hostname).Subrouter().HandleFunc("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/ui", http.StatusMovedPermanently)
}))
srapi := router.PathPrefix("/cosmos").Subrouter()
srapi.HandleFunc("/api/status", StatusRoute)
@ -236,6 +225,10 @@ func StartServer() {
router = proxy.BuildFromConfig(router, config.ProxyConfig)
router.HandleFunc("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/ui", http.StatusMovedPermanently)
}))
if ((config.HTTPSCertificateMode == utils.HTTPSCertModeList["SELFSIGNED"] || config.HTTPSCertificateMode == utils.HTTPSCertModeList["PROVIDED"]) &&
tlsCert != "" && tlsKey != "") || (config.HTTPSCertificateMode == utils.HTTPSCertModeList["LETSENCRYPT"]) {
utils.Log("TLS certificate exist, starting HTTPS servers and redirecting HTTP to HTTPS")