Error with Bootstrap theme/internal paths
Added by Cory Rich 17 days ago
Hello,
I'm trying to get a basic working example of a navigation bar with the Bootstrap theme and seem to be stuck. I believe my issue boils down to either a fundamental misunderstanding of how doocroot/approot/resources-dir work -- I'm either not handling it properly in my code or I am using the wrong deployment options, or a combination of both. Hopefully you guys can point me in the right direction. I'm using Visual Studio 2022/console application project.
When I use relative paths in my launch options:
--approot="." --docroot="." --resources-dir="." --http-address 0.0.0.0 --http-port 8080
I get a pop-up error in the browser that Bootstrap cannot be loaded, console output:
** > [2024-Dec-04 10:38:20.614] 11400 [/ gPc1tZu99nCPTXsy] [warning] "WApplication: WApplication::addMetaHeader() with no effect" **
** > [2024-Dec-04 10:38:20.616] 11400 [/ gPc1tZu99nCPTXsy] [warning] "WApplication: Deploy-path ends with '/', using /?_= for internal paths" **
[2024-Dec-04 10:38:20.620] 11400 - [info] "wthttp: 127.0.0.1 GET /?wtd=gPc1tZu99nCPTXsy&request=style&page=1 HTTP/1.1 200 104"
[2024-Dec-04 10:38:20.621] 11400 - [info] "WebRequest: took 102.836 ms"
[2024-Dec-04 10:38:20.627] 11400 - [info] "wthttp: 127.0.0.1 GET /resources/themes/bootstrap/5/main.css HTTP/1.1 404 85"
[2024-Dec-04 10:38:20.628] 11400 - [info] "wthttp: 127.0.0.1 GET /resources/moz-transitions.css HTTP/1.1 404 85"
[2024-Dec-04 10:38:20.629] 11400 - [info] "wthttp: 127.0.0.1 GET /resources/themes/bootstrap/5/bootstrap-theme.min.css HTTP/1.1 404 85"
[2024-Dec-04 10:38:20.640] 11400 - [info] "wthttp: 127.0.0.1 GET /?wtd=gPc1tZu99nCPTXsy&sid=1699928452&webGL=true&scrW=1920&scrH=1080&tz=-300&tzS=America%2FNew_York&htmlHistory=true&deployPath=%2F&request=script&rand=1416528663 HTTP/1.1 200 29263"
[2024-Dec-04 10:38:20.642] 11400 - [info] "WebRequest: took 29.761 ms"
[2024-Dec-04 10:38:20.644] 11400 - [info] "wthttp: 127.0.0.1 GET /favicon.ico HTTP/1.1 404 85"
[2024-Dec-04 10:38:20.733] 11400 - [info] "wthttp: 127.0.0.1 POST /?wtd=gPc1tZu99nCPTXsy HTTP/1.1 200 48"
[2024-Dec-04 10:38:20.734] 11400 - [info] "WebRequest: took 1.116 ms"
I bolded the 2 lines referring to internal paths, which is my first question -- I'm not sure what I'm doing wrong to cause those, how do I address that? And does that relate to my issue of not being able to use relative paths in my launch options?
If I use hard coded paths in my launch options, the navbar and theme will work:
--approot="." --docroot="." --resources-dir="C:\repo\path\to\resources" --http-address 0.0.0.0 --http-port 8080
But I will still see these lines in the console output, plus a few 404's for the bootstrap files:
[2024-Dec-04 10:53:46.285] 5136 - [info] "WServer/wthttp: initializing built-in wthttpd"
[2024-Dec-04 10:53:46.290] 5136 - [info] "wthttp: started server: http://0.0.0.0:8080"
[2024-Dec-04 10:53:48.565] 5136 - [info] "Wt: session created (#sessions = 1)"
[2024-Dec-04 10:53:48.566] 5136 [/ JpVe3eZj2oxUA6dC] [info] "WEnvironment: UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0"
[2024-Dec-04 10:53:48.567] 5136 - [info] "wthttp: 127.0.0.1 GET / HTTP/1.1 200 3113"
[2024-Dec-04 10:53:48.568] 5136 - [info] "WebRequest: took 2.948 ms"
** [2024-Dec-04 10:53:48.615] 5136 [/ JpVe3eZj2oxUA6dC] [warning] "WApplication: WApplication::addMetaHeader() with no effect"**
** [2024-Dec-04 10:53:48.618] 5136 [/ JpVe3eZj2oxUA6dC] [warning] "WApplication: Deploy-path ends with '/', using /?_= for internal paths"**
[2024-Dec-04 10:53:48.623] 5136 - [info] "wthttp: 127.0.0.1 GET /?wtd=JpVe3eZj2oxUA6dC&request=style&page=1 HTTP/1.1 200 104"
[2024-Dec-04 10:53:48.623] 5136 - [info] "WebRequest: took 45.049 ms"
** [2024-Dec-04 10:53:48.627] 5136 - [info] "wthttp: 127.0.0.1 GET /resources/themes/bootstrap/5/bootstrap-theme.min.css HTTP/1.1 404 85"**
[2024-Dec-04 10:53:48.628] 5136 - [info] "wthttp: 127.0.0.1 GET /resources/moz-transitions.css HTTP/1.1 200 6600"
[2024-Dec-04 10:53:48.629] 5136 - [info] "wthttp: 127.0.0.1 GET /resources/themes/bootstrap/5/main.css HTTP/1.1 200 227206"
[2024-Dec-04 10:53:48.640] 5136 - [info] "wthttp: 127.0.0.1 GET /?wtd=JpVe3eZj2oxUA6dC&sid=3301358496&webGL=true&scrW=1920&scrH=1080&tz=-300&tzS=America%2FNew_York&htmlHistory=true&deployPath=%2F&request=script&rand=2188236332 HTTP/1.1 200 29252"
[2024-Dec-04 10:53:48.640] 5136 - [info] "WebRequest: took 27.938 ms"
[2024-Dec-04 10:53:48.642] 5136 - [info] "wthttp: 127.0.0.1 GET /favicon.ico HTTP/1.1 404 85"
[2024-Dec-04 10:53:48.742] 5136 - [info] "wthttp: 127.0.0.1 POST /?wtd=JpVe3eZj2oxUA6dC HTTP/1.1 200 48"
[2024-Dec-04 10:53:48.742] 5136 - [info] "WebRequest: took 1.239 ms"
My project's repo directory is setup like:
C:\repo\TestApp\Output (Where Executable is generated)
Underneath /Output, I have the following folders:
- /approot (wt_config.xml lives here)
- /icons
- /resources
- favicon.ico
The /resources and /icons directories are direct copies from the Wt library. I have %WT_ROOT% defined as an environment variable, and %WT_ROOT%/bin in my %PATH% outside of Visual Studio. Within Visual Studio, the debugging environment is set to:
PATH=$(QtDllPath);%WT_ROOT%\bin;%PATH%$(LocalDebuggerEnvironment)
I've attached the sample files required to compile my code. In main.cpp on line 24, I have a setInternalPath("/") commented out. Setting this had no effect on my issues, even though it seems like I need to be handling that somehow.
Let me know if I can provide anything else.
Thanks,
Cory
main.cpp (1.24 KB) main.cpp | |||
NavBar.cpp (2.93 KB) NavBar.cpp | |||
NavBar.h (930 Bytes) NavBar.h |
Replies (2)
RE: Error with Bootstrap theme/internal paths - Added by Matthias Van Ceulebroeck 17 days ago
Hello Cory,
I believe my issue boils down to either a fundamental misunderstanding of how doocroot/approot/resources-dir work
the directories that can be configured, are still used as being directories. So if you say for example that approot="."
, the application will use the directory C:\repo\TestApp\Output
, and NOT C:\repo\TestApp\Output\approot
. The same goes for all other directories you specify.
So when the application then looks for the Bootstrap 5 theme, it will see you have the directory for resources equal to "."
, meaning C:\repo\TestApp\Output
, and look for the files it wants there, i.e. themes/bootstrap/5/bootstrap-theme.min.css
.
However, you DO define the docroot="."
. This will host all static files, so you CAN absolutely add your resource files there, in the resources
directory. This seems to exist in your project root of C:\repo\TestApp\Output
.
My guess would be that when you launch the application, that your root is NOT your working directory. All paths specified in the command are relative to the directory you reference them from. i.e. ("."
will be C:\repo\TestApp\Output
if that is your current working directory, or different if it is not).
I bolded the 2 lines referring to internal paths, which is my first question -- I'm not sure what I'm doing wrong to cause those, how do I address that?
This is not an error or problem at all, since you are using a deploy path (either configured from WServer::addEntryPoint() or with a command argument (--deploy-path
, see documentation). What happens here is that Wt is able to host multiple applications. These do need to be specified on different deployment paths. E.g. {url}/application1
and {url}/application2
. In this case there exists no confusion. However, if you use /
as the deployment path for either, Wt doesn't know whether {url}/{internalpath}
belongs to the application deployed at /
or the other one. So it uses /?_=
to make that distinction.
This is a technical side-effect, but nothing that will affect your problem. It' a warning, something to be aware of, but not an issue.
So to recap, I believe you simply have the working directory wrong, from which you launch the application.
I hope the explanation helped. If not, let me know. Or if you encounter any other problems.
Best,
Matthias
RE: Error with Bootstrap theme/internal paths - Added by Cory Rich 10 days ago
Hey Matthias,
Sorry for the delay, was out sick for a few days. You were correct though, turns out I forgot to update the "Working Directory" property under Configuration->Debugging that was sitting in front of my face the whole time :(. Corrected that and am back on track though, I appreciate the help!
Thanks,
Cory