ActivityPub/main.go

65 lines
1.7 KiB
Go
Raw Permalink Normal View History

2020-10-17 10:13:15 +00:00
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{"PostInbox", "POST", "/{actorName}/inbox/", collection.PostInboxHandler},
router.Route{"PostOutbox", "POST", "/{actorName}/outbox/", collection.PostOutboxHandler},
}
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)
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)
}
}