Routing to Endpoint

Hello,
I have a end point service that need to be configured after the authorization is configured.
I use ServiceStack AuthFeature.
This is the code that I use:

  app.UseServiceStack(appHost);
  app.UseEndpoints(endpoints =>
  {
    //...configure endpoint /path
  });

When I navigate to the endpoint path I don’t get a response.

If I bring the “App.UseEndpoints” before the “app.UseServicestack” I manage to get a response, but the user claim is alwais unauthenticated.

How I can manage to configure Servicestack to manage that route?

Thanks in advance

Hi @Gianmaria,

Can you share more about what you want to achieve with the separate endpoint? If you want ServiceStack to handle an endpoint, are you able to define a normal route/service for the specified path?

Are you trying to migrate a previously handled route to use ServiceStack.

Any additional details would be appreciate as I’m not sure I’m following what you are trying to achieve.

Hi,
for example I use Hotchocolate side by side with Servicestack.

For configure the end point I use this code:

       app.UseRouting();
      
        app.UseServiceStack(new AppHost
        {
            AppSettings = new NetCoreAppSettings(Configuration)
        });
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapGraphQL();
        });

The command endpoints.MapGraphQL(); create a route on “/graphql” endpoint and publish “Banana Cake Pop” Ui on that address.
When I call it by the browser I don’t get any response.

I suppose is due to the middleware pipeline order.

I investigated and I found that Sharpage plugin take care of the route so is not delivered to the right endpoint.

I added a IgnorePaths in SharpPage and everythings is ok.

     Plugins.Add(new SharpPagesFeature
  {
    IgnorePaths = new List<string>(){ "/graphql/*"}
  });

Thanks.

Gianmaria

2 Likes

Hi,
in the configuration above I enabled the SpaFallback feature
but after that the /graphql route is unreachable…

 Plugins.Add(new SharpPagesFeature
   {
    EnableSpaFallback = true,
    IgnorePaths = new List<string>(){ "/graphql/*"}
   });

I tried to manage manually the FallbackRoute but I did’t find a method to exclude specific paths.
Thanks.

Gianmaria

It’s a fallback route, so it’s going to catch all unhandled routes ServiceStack receives.

But you can programmatically control which requests it matches with a Custom Matching Rule, e.g. you can tell it to use a custom rule with:

[FallbackRoute("/{PathInfo*}", Matches="MyFallback")]
public class FallbackForClientRoutes
{
    public string PathInfo { get; set; }
}

Then define the rule in AppHost, in this case that the request is for html content-type and that the path doesn’t start with /graphql:

Config.RequestRules["MyFallback"] = req => 
    req.Accept?.IndexOf(MimeTypes.Html, StringComparison.Ordinal) >= 0 
    && !req.PathInfo.StartsWith("/graphql");

Perfect.
Thank you so much.

Gianmaria