CI / test (push) Successful in 4s
- Add test/integration.test.ts: getServicePublicKey, full flow (register, login, createCollection, createPointFeature, listFeatures) - Update docs example: registerBySigningServiceKey then loginWithSignature - Document integration tests in typescript-frontend-integration.md Made-with: Cursor
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"momswap/backend/internal/app"
|
|
httpapi "momswap/backend/internal/http"
|
|
"momswap/backend/internal/store"
|
|
)
|
|
|
|
func main() {
|
|
addr := getEnv("ADDR", ":8122")
|
|
adminPublicKey := os.Getenv("ADMIN_PUBLIC_KEY")
|
|
servicePublicKey := getEnv("SERVICE_PUBLIC_KEY", adminPublicKey)
|
|
|
|
if adminPublicKey == "" {
|
|
adminPublicKey = readKeyFile(getEnv("ADMIN_PUBLIC_KEY_FILE", "etc/server-service.pub"))
|
|
}
|
|
if servicePublicKey == "" {
|
|
servicePublicKey = readKeyFile(getEnv("SERVICE_PUBLIC_KEY_FILE", "etc/server-service.pub"))
|
|
}
|
|
if servicePublicKey == "" {
|
|
servicePublicKey = adminPublicKey
|
|
}
|
|
|
|
var st store.Store
|
|
if databaseURL := os.Getenv("DATABASE_URL"); databaseURL != "" {
|
|
if err := store.Migrate(databaseURL); err != nil {
|
|
log.Fatalf("migrate: %v", err)
|
|
}
|
|
pg, err := store.NewPostgresStore(databaseURL)
|
|
if err != nil {
|
|
log.Fatalf("postgres: %v", err)
|
|
}
|
|
defer pg.Close()
|
|
st = pg
|
|
} else {
|
|
st = store.NewMemoryStore()
|
|
}
|
|
|
|
service := app.NewService(st, app.Config{
|
|
ChallengeTTL: 5 * time.Minute,
|
|
SessionTTL: 24 * time.Hour,
|
|
}, servicePublicKey)
|
|
service.BootstrapAdmin(adminPublicKey)
|
|
|
|
api := httpapi.NewAPI(service)
|
|
log.Printf("listening on %s", addr)
|
|
if err := http.ListenAndServe(addr, api.Routes()); err != nil {
|
|
log.Fatalf("listen: %v", err)
|
|
}
|
|
}
|
|
|
|
func getEnv(key, fallback string) string {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
return fallback
|
|
}
|
|
return v
|
|
}
|
|
|
|
func readKeyFile(path string) string {
|
|
b, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return strings.TrimSpace(string(b))
|
|
}
|