How to refer to original node on 401 when you're rerouting with VHOST


#1

Enonic version: 6.13.1

We have a solution where we reroute a site to the root with VHOST (/no to /). We’ve also implemented a custom application to allow login via a Norwegian authentication service. As part of the login-experience we want to show some information from the original node that the user is trying to access. Now, as we use rerouting the path (and URL) is not aligned with the original node’s path (e.g. error.request.path will be /test, but original node path is /no/test).

Is there a way to infer the original path of the node without hardcoding?


#2

I didn’t figure this out, but found a solution little better than hardcoding, essentially using portalLib.getSite()._path to prefix original path that I’m looking at.

function getContent(path: string): IContentData<any> {
    const site = portalLib.getSite();
    const prefix = site._path;
    return contentLib.get({key: prefix + path}) || contentLib.get({key: path});
}

Here’s hoping it won’t have to much of a performance impact…


#3

What do you mean by “we reroute a site to the root with VHOST (/no to /)”? Could you maybe show parts of your site structure and vhost config?

NB! you should never mount a vhost to anything but a site, this will cause you many problems.


#4

Sorry for the long delay in response - I completely forgot about this thread.

My original question was how to refer to a node when the site it’s on uses some kind of routing (e.g. like we’ve done for most of our sites, where a node’s path is [domain]/no/test, but is public via [domain]/test). This was important since some nodes may return 401 as users didn’t have authorization, but we still wanted to display some data/info from the original node (i.e. title and description).

The problem arises when you use content.get in error.js (or handle401.js) to get the data without doing to much hardcoding. I found a solution using the above-mentioned solution.

Dunno if that did it any clearer? The problem is not VHOST specifically, but how to solve the referrer-problem when you use some kind of rerouting. I’ll leave this thread open in case there are better recommended solutions :slight_smile:


#5

Basically, If you are mounting a vhost to a path inside a site, say to site/no/ this is not recommended and may fail in several ways. Then you should rather make /no a site.