mirror of
https://github.com/acaloiaro/newsbox
synced 2026-07-21 10:12:26 +00:00
51 lines
1.1 KiB
Go
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())
|
|
}
|
|
}
|