Comments (9)
I would like it to work with
NEXT_PUBLIC_API_ENDPOINT=http://localhost:3000/api/v1
and
NEXT_PUBLIC_API_ENDPOINT=http://localhost:3000/api/v1/
from datx.
Just a thought.
Is it necessary to use url-join lib when we now have native support with new URL
https://developer.mozilla.org/en-US/docs/Web/API/URL/URL
const u = new URL('/todos', 'http://example.com/api/v1/');
u.toString()
// 'http://example.com/todos'
const u = new URL('/todos', 'http://example.com/api/v1')
u.toString()
// 'http://example.com/todos'
from datx.
@Jokasxy this line is the culprit https://github.com/infinum/datx/blob/master/packages/datx-jsonapi/src/helpers/url.ts#L158
I think if we wrapp it in new URL
it will fix the problem.
You can contribute if you have time.
@DarkoKukovec what do you think, am I right?
from datx.
@isBatak Like you have got there, you loose this "/api/v1" part like that so you would probably need to split the host from the rest in second param and append it before to the first param to use new URL
const path = 'tournament/1';
const apiURL = new URL(process.env.NEXT_PUBLIC_API_ENDPOINT as string);
const url = new URL(`${apiURL.href}${path.length <= 1 || path.startsWith('/') ? path : `/${path}`}`);
console.log(url.href);
// http://localhost:3000/api/v1/tournament/1
// same with /tournament/1
// path = '' gives http://localhost:3000/api/v1
// path = '/' gives http://localhost:3000/api/v1/
from datx.
Actually, it's this line: https://github.com/infinum/datx/blob/master/packages/datx-jsonapi/src/helpers/url.ts#L90
Is the issue that you have to add /
here? It seems to me that it's fine to be explicit here, because otherwise we're assuming that /
is always at the end, which might not be true?
from datx.
With this ${config.baseUrl}${url}
, slash character needs to be added either at the end of {baseUrl} or at the start of the {url} e.g. public static readonly endpoint = '/tournaments';
.
My idea adding a util function which will recognize how the url is formatted which could prevent zero and double slashes so we have a valid url anyhow.
from datx.
I agree with @Jokasxy double slashes should not happen.
I had this issue before and I scratched my head for some time until I figured out what was the problem.
from datx.
I guessd we could try to prevent double slashes, but I'm njot convinced we should add slashes if they don't exist.
from datx.
Final conclusion was to implement predictable url building that avoids double shals issue.
To opt-out from this decision endpoint should accept transformer function that receives baseUrl
and returns newly constructed endpoint.
config.baseUrl = 'http://example.com/api';
class Example extends jsonapi(Model) {
public static readonly endpoint = '_tournaments';
}
// endpoint: http://example.com/api/_tournaments
class Example extends jsonapi(Model) {
public static readonly endpoint = (baseUrl: string) => `${baseUrl}_tournaments`;
}
// endpoint: http://example.com/api_tournaments
from datx.
Related Issues (20)
- Map option not working properly with relationship. HOT 4
- Map option not working properly in combination with parse HOT 2
- Ability to send empty array or no relations on model.save() HOT 6
- Possible bug with generating post request HOT 3
- Cannot access 'Order' before initialization HOT 2
- [datx-jsonapi] - Support for node 18 fetch
- Search in documentation does not work properly HOT 2
- No export for setRefId
- [Proposal] - introduce new @Field decorator for jsonapi package instead of @Attribute
- Query parameters doubled
- mutate from useDatxInfinite doesn't work in useMutation HOT 1
- useMutation first parameter type error HOT 4
- Wrong return type on useDatxInfinite
- Error: [MobX] Cannot apply `@action` to `t.prototype.removeOne` HOT 4
- Object is empty inside client after upgrade to v3 HOT 13
- Handle instances of DatX models beeing passed to "getRawData" function.
- Handle response content type
- Project setup issues due to a different global lerna version
- Make datx work with native fetch on node 20 / drop use of `isomorphic-fetch`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datx.