Deploy path question and static docroot resources

Added by Emeric Poupon 3 months ago

Hello!

I use wthttpd with this:
--docroot=/usr/share/XXX/docroot;/resources,/css,/images,/js,/favicon.ico

In code:

useStyleSheet("css/XXX.css");
requireJQuery("js/jquery-1.10.2.min.js");
require("js/mediaplayer.js");
etc.


Everything is working just fine.

Now I want to use a deploy path, then I launched wthttpd using this extra config option:
--deploy-path=/XXX

Going to IP/XXX works, it seems to load my css file from IP/css/XXX.css and not from IP/XXX/css/XXX.css.
Some users report that messes up with reverse proxy.

Is that a wt bug or, I guess so, a bad configuration?

Regards,


Replies (6)

RE: Deploy path question and static docroot resources - Added by Roel Standaert 3 months ago

You are using relative paths for your stylesheets and JavaScript (they don't start with a '/'). This means that the browser will look for them relative to the current path. Seeing as the files from your docroot are being served at http(s)://yourdomain/, your CSS should be reachable at http(s)://yourdomain/css/XXX.css, and that's what you get when you use the path /css/XXX.css, starting with a slash.

But do you actually want your resources to be served from under your deployment path?

RE: Deploy path question and static docroot resources - Added by Emeric Poupon 3 months ago

Roel Standaert wrote:

You are using relative paths for your stylesheets and JavaScript (they don't start with a '/'). This means that the browser will look for them relative to the current path. Seeing as the files from your docroot are being served at http(s)://yourdomain/, your CSS should be reachable at http(s)://yourdomain/css/XXX.css, and that's what you get when you use the path /css/XXX.css, starting with a slash.

That's the two things I don't understand:
1- I use relative path (no leading /) in useStyleSheet() and require() and the browser still try to get them at root and not at the deploy path
2- these resources are actually reachable at root and not at the deploy path

But do you actually want your resources to be served from under your deployment path?

That's indeed what I want when I specify deploy-path.

RE: Deploy path question and static docroot resources - Added by Roel Standaert 3 months ago

I see. If you are at the path /foo, then css/XXX.css will indeed lead to /css/XXX.css, because it's starting from the current "directory". If you were at /foo/, then css/XXX.css would lead to /foo/css/XXX.css.

That's indeed what I want when I specify deploy-path.

That is not what deploy-path does. It only specifies where your default entrypoint is. Files in your docRoot are always served starting from '/'.

What you can do is create a folder in your docroot that is the same as your deploy-path, and make sure that your deploy-path ends with a slash. Note that if you are also using internal paths, you probably will want to use WApplication::resolveRelativeUrl() too.

RE: Deploy path question and static docroot resources - Added by Emeric Poupon 3 months ago

Ok thanks for your answer. It seems to work as you said. The only thing is that I didn't have to use resolveRelativeUrl (I use a lot of internal path, as you can see in https://lms.demo.poupon.io/)

The annoying thing is that I also have to create an intermediary directory for the Wt resources, which I point to using --resources-dir=/usr/share/Wt/resources.
As it not a good idea to modify this directory structure, I had to symlink /usr/share/XXX/docroot/XXX/resources -> /usr/share/Wt/resources.

Are you sure it would not make sense that docroot and --resources-dir use internally the deploy-path as a prefix? It would simplify deployment and I don't see drawbacks about this?

RE: Deploy path question and static docroot resources - Added by Roel Standaert 3 months ago

The only thing is that I didn't have to use resolveRelativeUrl

Yeah sorry, I was mistaken about that. The rendering code already resolves that.

Well, the common case is indeed that you have one entrypoint (usually with WRun), but it stops working when you have more entrypoints. I don't necessarily like the current situation myself, but I don't know if what you're suggesting is the solution either.

RE: Deploy path question and static docroot resources - Added by Emeric Poupon 3 months ago

Ok thanks for the support!
Actually I have something working so that's a good start, even if it feels a bit complicated.

(1-6/6)