Relative static file path and Pad names depend on the URL
See original GitHub issueDescribe the bug
Hello John, two dependencies blocking us, to make a plugin.
- Relative static files path, which depends on the URL path.
- 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
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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Yea if it’s stable it absolutely would land in develop > master/release 😃
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.