[MGNLFE-280] Uses relative url to build magnolia context object Created: 18/Jul/22  Updated: 23/Oct/23  Resolved: 27/Jul/22

Status: Closed
Project: Magnolia Frontend Helpers
Component/s: None
Affects Version/s: None
Fix Version/s: 1.3.0

Type: Improvement Priority: Neutral
Reporter: Phong Le Quoc Assignee: Bartosz Staryga
Resolution: Fixed Votes: 0
Labels: None
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: 1d 4.25h Time Spent: 4.75h
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Issue Links:
relation
is related to MGNLFE-232 Simplify usage of frontend-helpers wi... Closed
Sub-Tasks:
Key
Summary
Type
Status
Assignee
MGNLFE-285 Implementation Sub-task Completed Bartosz Staryga  
MGNLFE-286 Review Sub-task Completed Phong Le Quoc  
MGNLFE-287 PiQA Sub-task Completed Phong Le Quoc  
MGNLFE-288 QA Sub-task Completed Oanh Thai Hoang  
MGNLFE-302 DOCSub: Uses relative url to build ma... Documentation Task Closed Martin Drápela  
Template:
Acceptance criteria:
Empty
Task DoD:
[X]* Doc/release notes changes? Comment present?
[X]* Downstream builds green?
[X]* Solution information and context easily available?
[X]* Tests
[X]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:
Epic Link: Headless Phase 2
Sprint: DevX 15
Story Points: 1
Team: DeveloperX

 Description   

Currently, we need an absolute path to build Magnolia Context object. However, a relative path is enough. In addition, Angular Event API, React History API, and Vue Router API do not provide an absolute path. We must access low level window.location object to get the absolute path. Therefore, we should use relative path to build Magnolia Context object.

 

Note:



 Comments   
Comment by Bartosz Staryga [ 18/Jul/22 ]

If it's harder to get the full URL in some cases, then we should aim at supporting both: full URL, relative one.
It is important to keep in mind that we need the full gang there with search query params - but this is sth we put in docs I recon
the `new URL()` will throw us an error, but we can trick it by just adding a dummy base URL when a relative one is passed.
We do not really care about host so without need for extra libs (no need to bloat our js ) we can do maybe sth in this vibe:

function getUrl(string) {
  try {
    let url = 'http://valid-url.com';

    if (string.startsWith('http'))  {
      url = string;
    } else {
      if (string.startsWith('/')) {
        url += string
      } else {
        url += '/' + string
      }
    }

    return new URL(url);
  } catch (e) {
    console.warn('requestUrl is not a valid URL');

    return false;
  }
}
Comment by Bartosz Staryga [ 18/Jul/22 ]

Wdyt guys?

Comment by Phong Le Quoc [ 19/Jul/22 ]

Yeah

Comment by Bartosz Staryga [ 19/Jul/22 ]

plequocnot really sure how your workflow works too tricky jira
anyway I made a PR with proposed changed

Comment by Phong Le Quoc [ 21/Jul/22 ]

bstaryga 
I have added all necessary sub tasks for your ticket. You can merge your PR when piQA sub task are completed.

Comment by Bartosz Staryga [ 21/Jul/22 ]

Will do plequoc 👍

Generated at Mon Feb 12 05:45:54 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.