[bug] fetchModel fails when host and cqPath is passed

Open Beginner friendly
#288 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
frontend

Research direction

Inspect fetchModel.ts at line 58 and reproduce fetchModel({ cqPath, host }) with the provided URL example. Done means the formed URL retains https:// and fetchModel successfully downloads the JSON, matching the issue's expected behavior.

Written by the indexing model from the issue text.

Description

bug

Describe the bug
fetchModel functions failes to get the model when host and cqPath are passed as the url formed to fetch is incorrect

Package version
v2.1.0

To Reproduce
Steps to reproduce the behavior:

  1. invoke fetchModel({
    cqPath,
    host
    })
    where cqPath can be any path which can give json
    and host where this can be used
    example : fetch('https:/api.mockfly.dev/mocks/1a7495c9-1442-415f-b55c-5f5b3a2ed5f4/my-iqos-header.model.json')

Expected behavior
The fetch url should be correctly formed and work as expected to download json
in fetchModel.ts at line 58
const hostURL = sanitizeUrl(${host}/${path}).replace(//+/g, '/'); is the one causing the problem of replacing https:// to http:/ and due to which fetch for model.json fails
Better to replace this with
const fullUrl = new URL(cqPath, host).toString(); which gives the correct url

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Dominant language
TypeScript
Stars
68
Forks
35
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from adobe/aem-react-editable-components

All issues in adobe/aem-react-editable-components

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.