feat: add .well-known/webfinger
This commit is contained in:
parent
507b7349ba
commit
9bde1a1aa7
4 changed files with 133 additions and 0 deletions
|
@ -1,5 +1,10 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Core CoreConfig `toml:"core"`
|
||||
Web WebConfig `toml:"web"`
|
||||
|
@ -9,11 +14,34 @@ type Config struct {
|
|||
type WebConfig struct {
|
||||
// Domain should be the instance's full domain, including https:// but without the trailing slash.
|
||||
Domain string `toml:"domain"`
|
||||
// WebFingerDomain should be the instance's WebFinger domain, used for usernames.
|
||||
// .well-known/webfinger *must* listen on this domain.
|
||||
// It should only be the bare domain, i.e. `mercury.localhost`
|
||||
WebFingerDomain string `toml:"webfinger_domain"`
|
||||
|
||||
// Port is the port the server should listen on.
|
||||
Port int `toml:"port"`
|
||||
}
|
||||
|
||||
// WebFingerDomains returns the domains valid for WebFinger requests.
|
||||
// The first one is always the canonical domain.
|
||||
// This function is guaranteed to return at least one domain.
|
||||
func (c WebConfig) WebFingerDomains() []string {
|
||||
domains := make([]string, 0, 2)
|
||||
|
||||
if c.WebFingerDomain != "" {
|
||||
domains = append(domains, c.WebFingerDomain)
|
||||
}
|
||||
|
||||
u, err := url.Parse(c.Domain)
|
||||
if err != nil {
|
||||
return append(domains, strings.TrimPrefix(
|
||||
strings.TrimPrefix(c.Domain, "http://"), "https://"))
|
||||
}
|
||||
|
||||
return append(domains, u.Host)
|
||||
}
|
||||
|
||||
type CoreConfig struct {
|
||||
Postgres string `toml:"postgres"`
|
||||
Dev bool `toml:"dev"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue