newsbox/internal/buffalo.go
Adriano Caloiaro 8ae801ae5f
Initial commit
2023-02-15 08:57:48 -08:00

51 lines
1.1 KiB
Go

package internal
import (
"fmt"
"log"
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/envy"
)
var BuffaloConfig = buffalo.Options{
Env: Env(),
SessionName: "_newsbox_session",
}
func Env() string {
return envy.Get("GO_ENV", "development")
}
// SiteDomain returns the site domain
// Development default: localhost
// Production default: None. Site SITE_DOMAN
// When in development and `HOSTNAME` is set, that hostname will override "localhost"
// When in development and `HOSTNAME` is not set, and SITE_DOMAIN is set, it will override "localhost"
func SiteDomain() string {
if Env() == "development" {
return envy.Get("HOSTNAME", envy.Get("SITE_DOMAIN", "localhost"))
} else {
domain, err := envy.MustGet("SITE_DOMAIN")
if err != nil {
log.Fatalf("SITE_DOMAIN must be set in production")
}
return domain
}
}
// BaseUrl returns the URL where the application is avaialble
func BaseUrl() string {
devScheme := "http"
if SiteProtocol() != "" {
devScheme = "https"
}
if Env() == "development" {
return fmt.Sprintf("%s://%s", devScheme, SiteDomain())
} else {
return fmt.Sprintf("https://%s", SiteDomain())
}
}