Closed jgwinner closed 5 years ago
Tntnet has to know, what to do when a request arrives. For that there are mappings from url to the component. There are 2 methods to set those mappings. Either using a configuration file or in the program itself calling mapUrl. Both can also be combined.
By default nothing is loaded. Also there is no default "tntnet.xml", which is loaded. There is a process "tntnet", which reads the tntnet.xml. But nowadays I recommend to write your own main and instantiate a tnt::Tntnet object as you do in the above example.
If you want to read the tntnet.xml you have to do something like:
tnt::TntConfig cfg;
std::ifstream in("tntnet.xml");
in >> cxxtools::xml::Xml(cfg);
app.init(cfg);
or just recently I added a constructor for that, so that you can write:
tnt::Tntnet app(cfg);
Or you call mapUrl to map urls to the static component:
app.mapUrl("^/(.*)", "static@tntnet")
.setPathInfo("/var/www/htdocs/$1");
Maybe you want to add a default index.html:
app.mapUrl("^/index.html", "static@tntnet")
.setPathInfo("/var/www/htdocs/index.html");
app.mapUrl("^/(.*)/index.html", "static@tntnet")
.setPathInfo("/var/www/htdocs/$1/index.html");
Ah, got it!
I thought I tried the process method, and it didn't seem to work, but no doubt I didn't have it starting in the right place. In any event, the code above is what I needed to know, thank you!
== John ==
By the way - it might be a good idea to mention something like this in the docs under static files; that's what I missed (it's covered in other areas, so a reminder might be good or a link to those areas).
Ok, I've got a (hopefully) dumb question.
I checked the docs, and it says: http://www.tntnet.org/howto/static-howto.html
In tntnet.xml, I put the lines:
I'm using the basic sample:
Yet, I get 404 errors for any of the files I have loaded in /var/www/htdocs/
I've tried slightly different versions of the files to make sure I didn't have a typo or something.
Do we have to do something in the code to enable static files? Do I need a different app.mapURL statement? Does that bypass tntnet.xml? Do you need a statement to read tntnet.xml?
Thank you,
== John ==