mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 19:53:21 +02:00
This commit introduces a refactoring in various page templates to use a central, common 'head' section, stored under utilsHead.html. This head section contains common metadata, styles, and scripts. This change enhances code reusability and standardizes the head section across different pages for consistent user experience and ease of future potential changes. Also, some minimal adjustments were made in the navigation and link routing for more user-friendly URL paths. Lastly, the server's listening interface was updated to only listen on the localhost.
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"GohCMS2/api"
|
|
"GohCMS2/main/route"
|
|
"fmt"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/joho/godotenv"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
var possibleEnvFileLocations = []string{".env", "../.env"}
|
|
var envVarsToLoad = []string{"PORT", "ENVIRONMENT", "CORS_ALLOWED_ORIGINS", "DB_FILE"}
|
|
|
|
func initEnvVariables() {
|
|
var err error
|
|
for _, envLocation := range possibleEnvFileLocations {
|
|
err = godotenv.Load(envLocation)
|
|
if err == nil {
|
|
break
|
|
}
|
|
}
|
|
if err != nil {
|
|
fmt.Println("WARNING: Could not load any .env file")
|
|
}
|
|
|
|
for _, envVar := range envVarsToLoad {
|
|
if _, ok := os.LookupEnv(envVar); !ok {
|
|
panic(fmt.Sprintf("Environment variable %s is not set", envVar))
|
|
}
|
|
}
|
|
}
|
|
|
|
func InitServer() *chi.Mux {
|
|
initEnvVariables()
|
|
api.InitContainer()
|
|
api.InitValidator()
|
|
route.InitJwt()
|
|
return route.InitRoutes()
|
|
}
|
|
|
|
func StartServer(router *chi.Mux) error {
|
|
fmt.Println("Server starting on http://localhost:" + os.Getenv("PORT"))
|
|
err := http.ListenAndServe("localhost:"+os.Getenv("PORT"), router)
|
|
return err
|
|
}
|