-
Notifications
You must be signed in to change notification settings - Fork 3
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
any ways to specify base url? (escaped literal sections) #20
Comments
Hi, unfortunately due to the fact that the default template literal string mechanism does not apply here, currently it's not possible to parametrize routes this way. However I think there's an ugly workaround where you could derive from PathParamDescription. Then you need to override the If you need I could try to implement the solution above, see if it works and share it. The case you described should be however implemented as first class, with |
Hi, could you elaborate a bit on your use case? I believe we haven't ever imagined managing API endpoints (I assume this is what you're trying to do) to be a feature we'd like to cover with this package. Now that you mention it, it actually looks like it's something Are you trying to prefix all routes created with function fetchFromApi(path: string /*, ...otherParams */) {
return fetch(API_BASE_URL + path /*, other params */);
} It should also be possible to write a wrapper around the whole const apiRoutes = withBaseUrl(API_BASE_URL)(
createRouting({
getProfiles: segment`/api/profiles`,
}),
);
// and then for example if API_BASE_URL === 'https://localhost:4000', it yields this
apiRoutes.getProfiles() // 'https://localhost:4000/api/profiles'
// while the pattern for matching the path would be left untouched
apiRoutes.getProfiles.pattern // '/api/profiles' Would such a functionality cover your use case? It might be something to consider adding either to this package or even as some sort of an external package that builds on top of this, as I don't think |
Hey folks thanks for getting back to this for me. Yes indeed the usecase would be for having one place to have all the API endpoints in one place. Backend is hosted in a different domain and we don't want to add a proxy (e.g. Specifically we are using Since we have to use full paths, we are currently using a simple object map like so
which obv works... but its a bit inconsistent with what we do for Application routes, where we use ts-routes. All that said, I think the latter baseURL approach would definitely suffice! I think the configuration could also be done this way too? not sure what the "options" object is being used for atm.
|
+1 on this! We have a similar requirement where we're joining outputs of routs with a base URL. We'll manually implement a |
Hey, we looked back on that and we'll have it done for you as soon as possible. |
Is it possible to achieve something like this where we escape a literal section and actually attach the literal if desired.
This results in
undefined/api/profiles
The text was updated successfully, but these errors were encountered: