diff --git a/lib/hero/heroserver/auth.v b/lib/hero/heroserver/auth.v index 573b906a..1d98aee3 100644 --- a/lib/hero/heroserver/auth.v +++ b/lib/hero/heroserver/auth.v @@ -5,6 +5,12 @@ import crypto.ed25519 import rand import time +pub struct AuthConfig { +pub mut: + // Add any authentication-related configuration here + // For now, it can be empty or have default values +} + pub struct AuthManager { mut: registered_keys map[string]string // pubkey -> user_id @@ -28,7 +34,9 @@ pub: expires_at i64 } -pub fn new_auth_manager() &AuthManager { +pub fn new_auth_manager(config AuthConfig) &AuthManager { + // Use config if needed, for now it's just passed + _ = config return &AuthManager{} } diff --git a/lib/hero/heroserver/server.v b/lib/hero/heroserver/server.v index 96b776e0..69e2a5af 100644 --- a/lib/hero/heroserver/server.v +++ b/lib/hero/heroserver/server.v @@ -2,12 +2,22 @@ module heroserver import veb import freeflowuniverse.herolib.schemas.jsonrpc +import freeflowuniverse.herolib.crypt +import freeflowuniverse.herolib.heroserver.auth +import freeflowuniverse.herolib.heroserver.handlers + +pub struct ServerConfig { +pub mut: + port int = 8080 + auth_config auth.AuthConfig +} pub struct HeroServer { pub mut: config ServerConfig - auth_manager &AuthManager - handler_registry &HandlerRegistry + auth_manager &auth.AuthManager + handler_registry &handlers.HandlerRegistry + age_client &crypt.AGEClient } pub struct Context { @@ -57,7 +67,7 @@ pub fn (mut s HeroServer) api(mut ctx Context) veb.Result { request := jsonrpc.decode_request(ctx.req.data) or { return ctx.request_error('Invalid JSON-RPC request') } - + response := handler.handle(request) or { return ctx.server_error('Handler error') } return ctx.json(response) @@ -78,3 +88,17 @@ pub fn (mut s HeroServer) doc(mut ctx Context) veb.Result { return ctx.html(doc_html) } + +// new_server creates a new HeroServer instance +pub fn new_server(config ServerConfig) !&HeroServer { + mut auth_manager := auth.new_auth_manager(config.auth_config)! + mut handler_registry := handlers.new_handler_registry()! + mut age_client := crypt.new_age_client(crypt.AGEClientConfig{})! + + return &HeroServer{ + config: config + auth_manager: auth_manager + handler_registry: handler_registry + age_client: age_client + } +}