2

The problem definition

On my page, www.xxx.com/page, there is a script:

<script type="text/javascript" src="main.1234.js"></script>

Browser relolves it as www.xxx.com/main.1234.js instead of www.xxx.com/page/main.1234.js


More details about my setup

In fact, there are two applications running on the same server machine:

  • www.xxx.com/ (app #1)
  • www.xxx.com:82/ (app #2)

The page actually exists in the app #2 as www.xxx.com:82/page. If I access the page directly, then everything works as it should work (i.e. browser resolves links as expected).

But my setup is a bit more complicated. My goal is to hide app #2 from any public access, and make it available only via app #1 as www.xxx.com/page. In order to achieve that, I setup app #1 so, that if a user requests www.xxx.com/page, then app #1 under the hood performs a request to www.xxx.com:82/page of app #2 and returns received content back to the user.

From user's point of view everything should look like content of www.xxx.com:82/page resides under www.xxx.com/page. And it almost works. The only problem is that for some reason browser resolves URLs as I described under "The problem definition". How to fix it?


Additional info, hope it may help

I suppose, that an answer should be hidden in the responces. I suppose, that a cause is that the browser receives different response headers. The following are lists of headers the browser receives in each of these two cases:

  1. Response from app #1 (www.xxx.com/page) where browser incorrectly resolves URLs:
  • Cache-Control:private
  • Content-Length:775
  • Content-Type:text/html;charset=UTF-8
  • Date:Fri, 19 Jan 2018 11:34:40 GMT
  • Expires:Thu, 01 Jan 1970 00:00:00 UTC
  • Set-Cookie:zimidy-initialSessionIdHash=-226086716; Path=/
  • Strict-Transport-Security:max-age=31536000 ; includeSubDomains
  • X-Content-Type-Options:nosniff
  • X-Frame-Options:SAMEORIGIN
  • X-XSS-Protection:1; mode=block
  1. Response from app #2 (www.xxx.com:82/page) where browser correctly resolves URLs:
  • Accept-Ranges:bytes
  • Cache-Control:public, max-age=0
  • Connection:keep-alive
  • Date:Fri, 19 Jan 2018 11:33:16 GMT
  • ETag:W/"307-1610e1964c4"
  • Last-Modified:Fri, 19 Jan 2018 11:06:40 GMT
  • X-Powered-By:Express
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
Victor Dombrovsky
  • 2,955
  • 3
  • 21
  • 33

2 Answers2

0

The URL of

main.1234.js

starts from the location your page is in. The URL of

/main.1234.js

starts from the location of the baseurl. You have problably meant the baseurl. If your path is foo/bar/mypage, then linking main.1234.js will search for the file in foo/bar/. If you put a slash to the start, it will search for the file in the baseurl, which should be the root folder.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • This is exactly what I expected. But it works differently, which is why I asked the question. Actually, RolandStarke commented with an answer, that helped to fix the problem. Anyway, thanks for your answer! – Victor Dombrovsky Jan 21 '18 at 04:56
0

RolandStarke gave me an advice, which helped me to solve the problem.

Also, an explanation of the behaviour can be found here.


To make relative URLs to work properly, ending slash is required. I used it in the link from app #2, but not in the link from app #1. After addition of ending slash, everything started to work.

  • So, this link doesn't work properly: www.xxx.com/app
  • But this one, with ending slash, does work as expected: www.xxx.com/app/
Victor Dombrovsky
  • 2,955
  • 3
  • 21
  • 33