2023-01-25 05:47:06 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2024-08-15 00:38:38 +00:00
|
|
|
"git.devvul.com/asara/gologger"
|
|
|
|
"git.devvul.com/asara/well-goknown/config"
|
|
|
|
"git.devvul.com/asara/well-goknown/db"
|
2024-08-31 18:10:32 +00:00
|
|
|
"git.devvul.com/asara/well-goknown/lightningpub"
|
2024-08-15 00:38:38 +00:00
|
|
|
"git.devvul.com/asara/well-goknown/matrix"
|
|
|
|
"git.devvul.com/asara/well-goknown/nostr"
|
2024-08-14 03:09:59 +00:00
|
|
|
"github.com/fiatjaf/eventstore/postgresql"
|
2023-01-25 05:47:06 +00:00
|
|
|
)
|
|
|
|
|
2024-08-15 01:20:14 +00:00
|
|
|
var (
|
|
|
|
Version string
|
|
|
|
)
|
|
|
|
|
2023-01-25 05:47:06 +00:00
|
|
|
func main() {
|
2024-09-17 01:01:42 +00:00
|
|
|
l := gologger.Get(config.GetConfig().LogLevel).With().Caller().Logger()
|
2024-08-10 23:55:16 +00:00
|
|
|
db, _ := db.NewDB()
|
|
|
|
defer db.Close()
|
|
|
|
|
2024-08-31 18:10:32 +00:00
|
|
|
lightningpub.DB = db
|
2024-08-10 23:55:16 +00:00
|
|
|
nostr.DB = db
|
2024-08-14 03:09:59 +00:00
|
|
|
nostr.RelayDb = postgresql.PostgresBackend{DatabaseURL: config.GetConfig().DbUrl}
|
|
|
|
if err := nostr.RelayDb.Init(); err != nil {
|
|
|
|
l.Panic().Msgf("unable to connect to relay db: %s", err.Error())
|
|
|
|
}
|
2024-08-15 01:20:14 +00:00
|
|
|
relay := nostr.NewRelay(Version)
|
2023-05-06 23:50:10 +00:00
|
|
|
|
2023-02-03 04:56:15 +00:00
|
|
|
// matrix endpoints
|
2024-08-10 23:55:16 +00:00
|
|
|
l.Debug().Msg("enabling matrix well-known endpoints")
|
2023-02-04 01:15:41 +00:00
|
|
|
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
|
|
|
|
http.HandleFunc("/.well-known/matrix/client", matrix.MatrixClient)
|
2023-02-03 04:56:15 +00:00
|
|
|
|
|
|
|
// nostr endpoints
|
2024-08-10 23:55:16 +00:00
|
|
|
l.Debug().Msg("enabling nostr well-known endpoints")
|
2023-01-25 05:47:06 +00:00
|
|
|
http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr)
|
2024-08-14 03:09:59 +00:00
|
|
|
http.Handle("/relay", relay)
|
2023-12-31 01:12:01 +00:00
|
|
|
|
2024-08-31 18:10:32 +00:00
|
|
|
// lnurlp endpoint
|
|
|
|
l.Debug().Msg("enabling lnurlp well-known endpoint")
|
|
|
|
http.HandleFunc("/.well-known/lnurlp/{name}", lightningpub.GetLnurlp)
|
|
|
|
|
2023-02-03 04:56:15 +00:00
|
|
|
// start server
|
2023-04-29 18:01:40 +00:00
|
|
|
port := config.GetConfig().ListenAddr
|
|
|
|
l.Info().Msgf("starting server on %s", port)
|
|
|
|
http.ListenAndServe(port, nil)
|
2023-01-25 05:47:06 +00:00
|
|
|
}
|