ActivityPub/main.go
2020-10-17 12:13:15 +02:00

88 lines
2.7 KiB
Go

package main
import (
"crypto/tls"
"log"
"net/http"
"os"
"git.nutfactory.org/hoernschen/ActivityPub/config"
"git.nutfactory.org/hoernschen/ActivityPub/entities/actor"
"git.nutfactory.org/hoernschen/ActivityPub/entities/collection"
"git.nutfactory.org/hoernschen/ActivityPub/entities/object"
"git.nutfactory.org/hoernschen/ActivityPub/entities/user"
"git.nutfactory.org/hoernschen/ActivityPub/utils/database"
"git.nutfactory.org/hoernschen/ActivityPub/utils/router"
)
var keyPath = "./ssl.key"
var certPath = "./ssl.crt"
var routes = router.Routes{
// General
router.Route{"Reset", "GET", "/reset", config.Reset},
router.Route{"SetParams", "GET", "/setparams", config.SetParams},
// Users
router.Route{"Register", "POST", "/register", user.RegisterHandler},
// Actors
router.Route{"GetProfile", "GET", "/{actorName}/", actor.GetProfileHandler},
// Objects
router.Route{"GetPost", "GET", "/{actorName}/posts/{postId}", object.GetPostHandler},
// Collections
/*
router.Route{"GetInbox", "GET", "/{actorName}/inbox", collection.GetInboxHandler},
router.Route{"GetOutbox", "GET", "/{actorName}/outbox", collection.GetOutboxHandler},
router.Route{"GetFollowers", "GET", "/{actorName}/followers", collection.GetFollowersHandler},
router.Route{"GetFollowing", "GET", "/{actorName}/following", collection.GetFollowingHandler},
router.Route{"GetLiked", "GET", "/{actorName}/liked", collection.GetLikedHandler},
*/
router.Route{"PostInbox", "POST", "/{actorName}/inbox/", collection.PostInboxHandler},
router.Route{"PostOutbox", "POST", "/{actorName}/outbox/", collection.PostOutboxHandler},
/*
router.Route{"PostFollowers", "POST", "/{actorName}/followers", collection.PostFollowersHandler},
router.Route{"PostFollowing", "POST", "/{actorName}/following", collection.PostFollowingHandler},
router.Route{"PostLiked", "POST", "/{actorName}/liked", collection.PostLikedHandler},
*/
}
func main() {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
config.Homeserver = "localhost"
if len(os.Args) > 1 {
config.Homeserver = os.Args[1]
}
log.Printf("Start homeserver on name %s", config.Homeserver)
/*
if err := device.InitServerSigningKey(); err != nil {
log.Fatal(err)
}
config.VerifyKeys = make(map[string]map[string][]byte)
*/
/*
config.BackoffPolicy = backoff.NewExponential(
backoff.WithInterval(500*time.Millisecond),
backoff.WithMaxRetries(16),
)
*/
os.Remove("sqlite.db")
if err := database.InitDB("sqlite.db"); err != nil {
log.Fatal(err)
}
defer database.DB.Close()
config.SetDefaultParams()
router := router.NewRouter(routes)
httpErr := http.ListenAndServeTLS(":443", certPath, keyPath, router)
if httpErr != nil {
log.Fatal(httpErr)
}
}