package publisher
import (
"net/http"
"alin.ovh/x/log"
"github.com/Southclaws/fault"
"github.com/Southclaws/fault/fmsg"
"go.hacdias.com/indielib/indieauth"
"tailscale.com/client/local"
"alin.ovh/homestead/domain/web/server"
"alin.ovh/homestead/domain/web/templates"
"alin.ovh/homestead/shared/config"
ihttp "alin.ovh/homestead/shared/http"
)
type Options struct {
Development bool `conf:"-"`
BaseURL config.URL
VCSRemoteURL config.URL `conf:"default:https://git.alin.ovh/website"`
LocalClient *local.Client `conf:"-"`
}
type App struct {
log *log.Logger
indieauthServer *indieauth.Server
siteSettings templates.SiteSettings
localClient *local.Client
*server.App
}
func New(opts *Options, log *log.Logger) (*App, error) {
var err error
app := &App{
log: log,
indieauthServer: indieauth.NewServer(true, &http.Client{}),
localClient: opts.LocalClient,
siteSettings: templates.SiteSettings{
Title: "Barkeep",
Language: "en-GB",
Menu: []config.MenuItem{},
InjectLiveReload: opts.Development,
},
App: &server.App{
Domain: opts.BaseURL.Hostname(),
Shutdown: func() {},
},
}
if opts.BaseURL.Path == "" {
opts.BaseURL.Path = "/"
}
err = indieauth.IsValidProfileURL(opts.BaseURL.String())
if err != nil {
return nil, fault.Wrap(err, fmsg.With("invalid base URL"))
}
mux := ihttp.NewServeMux(log.Named("http"))
mux.HandleFunc("/", app.WithUserContext(app.Index))
mux.HandleFunc("/style.css", app.Style)
app.Handler = mux
return app, nil
}
domain/content/publisher/app.go (view raw)