question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative static file path and Pad names depend on the URL

See original GitHub issue

Describe the bug

Hello John, two dependencies blocking us, to make a plugin.

  1. Relative static files path, which depends on the URL path.
  2. Pad name, which the pad management system also gets that name from the URL path.

What do I want to achieve with the plugin?

I’m going to create a sub pad! like this one /p/:pad/:subpad. the navigation flow is so simple. when a user navigates to, i have to sever pad.html. so far there is not any problem.

My router function for sub pad (like the original one):

  args.app.get('/p/:pad/:view', function(req, res) {
    const {pad, view} = req.params

    // The below might break for pads being rewritten
    var isReadOnly = req.url.indexOf("/p/r.") === 0;

    hooks.callAll("padInitToolbar", {
      toolbar: toolbar,
      isReadOnly: isReadOnly
    });

    res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {
      req: req,
      toolbar: toolbar,
      isReadOnly: isReadOnly
    }));

  })

Notes: here we don’t ever use req in that file! why do you pass it to eejs (At least I don’t know how it’s handy). suggestion: It would be good to pass the pad name here to remove dependency on URL. (I did not go deep into the Etherpad core to realize why you make this decision, maybe there is a reason.)

Okay let’s continue, Every problem pops up when the pad.html generates and renders on the client-side.

These are the logs when i look up the network tab of the browser:

/p/:pad
Request URL: http://localhost:9001/static/js/html10n.js?v=36cee976
Status Code: 200

/p/:pad/:subPad
Request URL: http://localhost:9001/p/static/js/html10n.js?v=1a7ddb6c
Status Code: 404 Not Found

/p/:pad/:subPad/:view
Request URL: http://localhost:9001/p/static/js/html10n.js?v=1a7ddb6c
Status Code: 404 Not Found

image

So what’s happening here! and what was the strategy that caused these problems is the main question?

I took a look at the code and found out the two reasons that I mentioned in the beginning.

1.Relative static files path, which depends on the URL path

These lines in pad.html have a relative path and depend on the URL, if the URL changes, the client can not resolve paths then they get 404 status code.

suggestion: If it’s possible, I do suggest resolving these paths in the template engine.

45: <link href="../static/css/pad.css?v=<%=settings.randomVersionString%>" rel="stylesheet">
48: <link href="../static/skins/<%=encodeURI(settings.skinName)%>/pad.css?v=<%=settings.randomVersionString%>" rel="stylesheet">
55: <script type="text/javascript" src="../static/js/html10n.js?v=<%=settings.randomVersionString%>"></script>
56: <script type="text/javascript" src="../static/js/l10n.js?v=<%=settings.randomVersionString%>"></script>
438: <script type="text/javascript" src="../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
441: <script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad_utils.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>

464: <script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>

465: <script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>

468: <script type="text/javascript" src="../static/skins/<%=encodeURI(settings.skinName)%>/pad.js?v=<%=settings.randomVersionString%>"></script>

481: require.setRootURI(baseURL + "javascripts/src");
482: require.setLibraryURI(baseURL + "javascripts/lib");

2.Pad name, which the pad management system also gets that name from the URL path

If we resolve the first issue, then all files resolve correctly, but after all the second one shows up!

In the files like pad.js when the sendClientReady function call, it makes padId with location.pathname. (stateful design)

// /etherpad-lite/src/templates/pad.html
143: var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);

e.g. if a user is in this route /p/padname/view, the code takes the last part of the location path for the pad name which is view in this case. In this way the pad name is okay, but the question is, what should we do in the server-side (from middleware to router)?

I hope I have fully explained what i want.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
JohnMcLearcommented, Jul 30, 2020

Yea if it’s stable it absolutely would land in develop > master/release 😃

0reactions
stale[bot]commented, Jan 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Absolute vs relative URLs - Stack Overflow
This URL is relative to the current path. What this means is that it will resolve to different paths depending on where you...
Read more >
Using relative paths to link handbook pages
You can take a look at this video of Jean explaining relative paths and how they work. To sum up, the path described...
Read more >
Absolute vs. Relative Paths/Links - CoffeeCup Software
The first difference you'll notice between the two different types of links is that absolute paths always include the domain name of the...
Read more >
URL Management - Hugo
URL Management. Hugo supports permalinks, aliases, link canonicalization, and multiple options for handling relative vs absolute URLs. Permalinks.
Read more >
HTML File Paths | Absolute vs Relative URLs - YouTube
In this video I talk about HTML Document File Paths as they relate to Absolute and Relative URL's. Being able to navigate your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found