95 lines
2.5 KiB
Go
95 lines
2.5 KiB
Go
// TODO: Add EUPL banner everywhere
|
|
package main
|
|
|
|
import (
|
|
"embed"
|
|
"flag"
|
|
"time"
|
|
|
|
"git.mstar.dev/mstar/goutils/other"
|
|
"github.com/go-webauthn/webauthn/webauthn"
|
|
"github.com/mstarongithub/passkey"
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"git.mstar.dev/mstar/linstrom/config"
|
|
"git.mstar.dev/mstar/linstrom/server"
|
|
"git.mstar.dev/mstar/linstrom/shared"
|
|
"git.mstar.dev/mstar/linstrom/storage"
|
|
"git.mstar.dev/mstar/linstrom/storage/cache"
|
|
)
|
|
|
|
// TODO: Add frontend overwrite
|
|
// Serve frontend files from a given directory instead of embedded data
|
|
|
|
//go:embed frontend-reactive/dist/* frontend-reactive/dist/assets
|
|
var reactiveFS embed.FS
|
|
|
|
//go:embed frontend-noscript
|
|
var nojsFS embed.FS
|
|
|
|
//go:embed duck.webp
|
|
var defaultDuck string
|
|
|
|
func main() {
|
|
other.SetupFlags()
|
|
flag.Parse()
|
|
other.ConfigureLogging(nil)
|
|
if err := config.ReadAndWriteToGlobal(*shared.FlagConfigFile); err != nil {
|
|
log.Fatal().
|
|
Err(err).
|
|
Str("config-file", *shared.FlagConfigFile).
|
|
Msg("Failed to read config and couldn't write default")
|
|
}
|
|
|
|
// Request to only check config
|
|
if *shared.FlagConfigOnly {
|
|
return
|
|
}
|
|
|
|
storageCache, err := cache.NewCache(
|
|
config.GlobalConfig.Storage.MaxInMemoryCacheSize,
|
|
config.GlobalConfig.Storage.RedisUrl,
|
|
)
|
|
if err != nil {
|
|
log.Fatal().Err(err).Msg("Failed to start cache")
|
|
}
|
|
|
|
// var store *storage.Storage
|
|
// if config.GlobalConfig.Storage.DbIsPostgres != nil && *config.GlobalConfig.Storage.DbIsPostgres {
|
|
// store, err = storage.NewStoragePostgres(config.GlobalConfig.Storage.DatabaseUrl, storageCache)
|
|
// } else {
|
|
// store, err = storage.NewStorageSqlite(config.GlobalConfig.Storage.DatabaseUrl, storageCache)
|
|
// }
|
|
//
|
|
store, err := storage.NewStorage(config.GlobalConfig.Storage.BuildPostgresDSN(), storageCache)
|
|
|
|
if err != nil {
|
|
log.Fatal().Err(err).Msg("Failed to setup storage")
|
|
}
|
|
|
|
pkey, err := passkey.New(passkey.Config{
|
|
WebauthnConfig: &webauthn.Config{
|
|
RPDisplayName: "Linstrom",
|
|
RPID: "localhost",
|
|
RPOrigins: []string{"http://localhost:8000"},
|
|
},
|
|
UserStore: store,
|
|
SessionStore: store,
|
|
SessionMaxAge: time.Hour * 24,
|
|
}, passkey.WithLogger(&shared.ZerologWrapper{}))
|
|
if err != nil {
|
|
log.Fatal().Err(err).Msg("Failed to setup passkey support")
|
|
}
|
|
|
|
server := server.NewServer(
|
|
store,
|
|
pkey,
|
|
shared.NewFSWrapper(reactiveFS, "frontend-reactive/dist/", false),
|
|
shared.NewFSWrapper(nojsFS, "frontend-noscript/", false),
|
|
&defaultDuck,
|
|
)
|
|
server.Start(":8000")
|
|
// TODO: Set up media server
|
|
// TODO: Set up queues
|
|
// TODO: Set up plugins
|
|
}
|