Move Host config value from Server -> App

This commit is contained in:
Matt Baer 2018-10-27 17:02:40 -04:00
parent ad3b813690
commit e6f1291189
5 changed files with 7 additions and 8 deletions

View file

@ -10,7 +10,6 @@ const (
type ( type (
ServerCfg struct { ServerCfg struct {
Host string `ini:"host"`
Port int `ini:"port"` Port int `ini:"port"`
} }
@ -25,6 +24,7 @@ type (
AppCfg struct { AppCfg struct {
SiteName string `ini:"site_name"` SiteName string `ini:"site_name"`
Host string `ini:"host"`
// Site appearance // Site appearance
Theme string `ini:"theme"` Theme string `ini:"theme"`
@ -52,7 +52,6 @@ type (
func New() *Config { func New() *Config {
return &Config{ return &Config{
Server: ServerCfg{ Server: ServerCfg{
Host: "http://localhost:8080",
Port: 8080, Port: 8080,
}, },
Database: DatabaseCfg{ Database: DatabaseCfg{
@ -61,6 +60,7 @@ func New() *Config {
Port: 3306, Port: 3306,
}, },
App: AppCfg{ App: AppCfg{
Host: "http://localhost:8080",
Theme: "write", Theme: "write",
WebFonts: true, WebFonts: true,
SingleUser: true, SingleUser: true,

View file

@ -42,9 +42,9 @@ func Configure() error {
prompt = promptui.Prompt{ prompt = promptui.Prompt{
Label: "Public-facing host", Label: "Public-facing host",
Validate: validateDomain, Validate: validateDomain,
Default: c.Server.Host, Default: c.App.Host,
} }
c.Server.Host, err = prompt.Run() c.App.Host, err = prompt.Run()
if err != nil { if err != nil {
return err return err
} }

View file

@ -15,7 +15,7 @@ type nodeInfoResolver struct {
func nodeInfoConfig(cfg *config.Config) *nodeinfo.Config { func nodeInfoConfig(cfg *config.Config) *nodeinfo.Config {
name := cfg.App.SiteName name := cfg.App.SiteName
return &nodeinfo.Config{ return &nodeinfo.Config{
BaseURL: cfg.Server.Host, BaseURL: cfg.App.Host,
InfoURL: "/api/nodeinfo", InfoURL: "/api/nodeinfo",
Metadata: nodeinfo.Metadata{ Metadata: nodeinfo.Metadata{

View file

@ -12,8 +12,7 @@ import (
func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datastore) { func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datastore) {
isSingleUser := !cfg.App.MultiUser isSingleUser := !cfg.App.MultiUser
// Write.as router hostSubroute := cfg.App.Host[strings.Index(cfg.App.Host, "://")+3:]
hostSubroute := cfg.Server.Host[strings.Index(cfg.Server.Host, "://")+3:]
if isSingleUser { if isSingleUser {
hostSubroute = "{domain}" hostSubroute = "{domain}"
} else { } else {

View file

@ -27,7 +27,7 @@ func initSession(app *app) *sessions.CookieStore {
Path: "/", Path: "/",
MaxAge: sessionLength, MaxAge: sessionLength,
HttpOnly: true, HttpOnly: true,
Secure: strings.HasPrefix(app.cfg.Server.Host, "https://"), Secure: strings.HasPrefix(app.cfg.App.Host, "https://"),
} }
return store return store
} }