Reputation: 11458
I have a self-hosted application with many routes set up. Rather than going through each one and changing the route to be /api/<route>
where <route>
is the existing route, I was wondering if I can prefix each route with /api
when I start the application? I know its possible in an IIS hosted enviroment by setting it in the web.config
but I am not sure if its possible in a self-hosted environment?
Upvotes: 2
Views: 754
Reputation: 9763
According To this ServiceStack article you just need to set it through the config, like this:
public override void Configure(Container container)
{
SetConfig(new HostConfig { HandlerFactoryPath = "api" });
}
Combine that with this answer from Mythz and you got yourself a self-hosted app at /api/
:
_apphost.Start("http://localhost:1337/api/");
Note: this seems to have worked for the self-hosted API, but then it fails to serve up its razor pages. So this isn't quite right. Still, leaving the answer for now until a full solution is found.
Upvotes: 4
Reputation: 21511
@EliGassert's answer is right for ServiceStack v4 self-hosted applications. This is the requirements to change the base path of all routes in a ServiceStack v3 self-hosted application.
In you AppHost Configure
method, you need to set ServiceStackHanderFactoryPath
to the desired prefix.
public override void Configure(Container container)
{
SetConfig(new EndpointHostConfig {
ServiceStackHandlerFactoryPath = "api"
});
}
When you set your listener you must also append the prefix:
appHost.Start("http://*:9000/api/");
Hope that helps.
Upvotes: 5