domain/content/publisher/app.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | package publisher
import (
"net/http"
"github.com/Southclaws/fault"
"github.com/Southclaws/fault/fmsg"
"go.hacdias.com/indielib/indieauth"
"alin.ovh/homestead/domain/web/server"
"alin.ovh/homestead/domain/web/templates"
"alin.ovh/homestead/shared/config"
ihttp "alin.ovh/homestead/shared/http"
"alin.ovh/x/log"
)
type Options struct {
Development bool `conf:"-"`
BaseURL config.URL
VCSRemoteURL config.URL `conf:"default:https://git.alin.ovh/website"`
}
type App struct {
log *log.Logger
indieauthServer *indieauth.Server
siteSettings templates.SiteSettings
*server.App
}
func New(opts *Options, log *log.Logger) (*App, error) {
var err error
app := &App{
log: log,
indieauthServer: indieauth.NewServer(true, &http.Client{}),
siteSettings: templates.SiteSettings{
Title: "Barkeep",
Language: "en-GB",
Menu: []config.MenuItem{},
InjectLiveReload: opts.Development,
},
App: &server.App{
Domain: opts.BaseURL.Hostname(),
Shutdown: func() {},
},
}
err = indieauth.IsValidProfileURL(opts.BaseURL.String())
if err != nil {
return nil, fault.Wrap(err, fmsg.With("invalid base URL"))
}
mux := ihttp.NewServeMux()
mux.HandleFunc("/", app.Index)
mux.HandleFunc("/style.css", app.Style)
app.Handler = mux
return app, nil
}
|