diff --git a/src/SimpleW/Router.cs b/src/SimpleW/Router.cs index d94e74c..59db759 100644 --- a/src/SimpleW/Router.cs +++ b/src/SimpleW/Router.cs @@ -632,7 +632,8 @@ public void MapFallback(Delegate handler) { #region not found - private static readonly HttpRouteExecutor _notFoundExecutor = RouteExecutorFactory.Create(static (HttpSession s) => s.Response.Status(404).Text("Not Found").SendAsync()); + // a plain HttpRouteExecutor rather than RouteExecutorFactory.Create() : a Delegate handler is compiled from an expression tree, which fails under NativeAOT + private static readonly HttpRouteExecutor _notFoundExecutor = static (session, _) => session.Response.Status(404).Text("Not Found").SendAsync(); #endregion not found diff --git a/src/SimpleW/modules/ServerSentEventsModule.cs b/src/SimpleW/modules/ServerSentEventsModule.cs index fe53fc4..23a8265 100644 --- a/src/SimpleW/modules/ServerSentEventsModule.cs +++ b/src/SimpleW/modules/ServerSentEventsModule.cs @@ -127,10 +127,11 @@ public ServerSentEventsModule(ServerSentEventsOptions options) { /// /// public void Install(SimpleWServer server) { + // map an HttpRouteExecutor rather than a Delegate : a Delegate handler is compiled from an expression tree, which fails under NativeAOT // accept prefix - server.MapGet(_options.Prefix, (HttpSession session) => HandlerAsync(session)); + server.Router.Map("GET", _options.Prefix, (session, _) => HandlerAsync(session)); // accept prefix wildcard as fallback (but will enforce exact match) - server.MapGet(_options.PrefixWildCard, (HttpSession session) => HandlerAsync(session)); + server.Router.Map("GET", _options.PrefixWildCard, (session, _) => HandlerAsync(session)); _log.Info($"installed with prefix {_options.Prefix}"); } diff --git a/src/SimpleW/modules/StaticFilesModule.cs b/src/SimpleW/modules/StaticFilesModule.cs index 5799758..1cfaa7b 100644 --- a/src/SimpleW/modules/StaticFilesModule.cs +++ b/src/SimpleW/modules/StaticFilesModule.cs @@ -219,8 +219,9 @@ public void Install(SimpleWServer server) { } // map GET + HEAD - server.MapGet(_options.PrefixWildCard, (HttpSession session) => HandlerAsync(session)); - server.Map("HEAD", _options.PrefixWildCard, (HttpSession session) => HandlerAsync(session)); + // map an HttpRouteExecutor rather than a Delegate : a Delegate handler is compiled from an expression tree, which fails under NativeAOT + server.Router.Map("GET", _options.PrefixWildCard, (session, _) => HandlerAsync(session)); + server.Router.Map("HEAD", _options.PrefixWildCard, (session, _) => HandlerAsync(session)); _log.Info($"installed with prefix {_options.Prefix}"); } diff --git a/src/SimpleW/modules/WebSocketModule.cs b/src/SimpleW/modules/WebSocketModule.cs index 5998855..d34c170 100644 --- a/src/SimpleW/modules/WebSocketModule.cs +++ b/src/SimpleW/modules/WebSocketModule.cs @@ -191,10 +191,11 @@ public WebSocketModule(WebSocketOptions options) { /// /// public void Install(SimpleWServer server) { + // map an HttpRouteExecutor rather than a Delegate : a Delegate handler is compiled from an expression tree, which fails under NativeAOT // accept prefix - server.MapGet(_options.Prefix, (HttpSession session) => HandlerAsync(session)); + server.Router.Map("GET", _options.Prefix, (session, _) => HandlerAsync(session)); // accept prefix wildcard as fallback (but will enforce exact match) - server.MapGet(_options.PrefixWildCard, (HttpSession session) => HandlerAsync(session)); + server.Router.Map("GET", _options.PrefixWildCard, (session, _) => HandlerAsync(session)); _log.Info($"installed with prefix {_options.Prefix}"); }