-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set BaseUrl for Typescript clients? #1198
Comments
Which template did you select? |
Using the default Fetch template. I am making the calls from a react app. |
You can provide the baseUrl with the first parameter of the constructor: Set server url to “.” without quotes |
I'm not going to hardcode a basePath into every call where I new a client. They're all going to be the same. All the client classes are from the same webapi project. Would be nice if there was a way in studio to set it. Or maybe if you generated some global class representing that webapi and then I set the basePath for that webapi config from typescript. |
I think you can just use the parameter |
My nswag.json is using the ServiceHost parameter. I am typing into the ServiceHost textbox in nswag studio. The issue is that I want to set a base PATH for the web api, not an entire url. I want the baseUrl to be the same as what the client is launched at, but the webapi is served from a different project. This is a common pattern. One project for the gui and one for the webapi on the same machine. To me there is: [SCHEME]://[HOST]/[PATH] What I have found using the service host setting is:
I would like baseUrl to just be "/ProjectWebApi". When I hand edit the generated code to just "/ProjectWebApi", everything works great. I just can't seem to get nswag to generate that way. I would like to keep the generated client api simple with simple constructors. The client objects should be able to take care of themselves, I shouldn't need to be entering everywhere the base PATH when I new the client objects. |
@hfirst It actually sets the |
I having the same problem. I am trying to use the this.baseUrl = baseUrl ? baseUrl : "http://"; |
NSwagStudio v11.15.3.0. Generating typescript client for C# web api controllers. My GUI is served from one url and the webapi is from another url (on the same machine). Just the path is different. I see in the generated ts file a baseUrl variable. This appears tied to the Studio's ServiceHost setting. I don't see any way to just provide a different path. If I set just the path into studio, '/MyProjectWebApi', it's prepending http: onto the beginning and it doesn't work. If I hand edit baseUrl to '/MyProjectWebApi', it does work.
Is there any way for me to set just an alternate path? but have it keep using whatever the app schema and host name was used?
If the ServiceHost starts with a '/', could it stop adding http? I tried experimenting with a '.', but no luck.
The text was updated successfully, but these errors were encountered: