Discussion:
[Wt-interest] How to use wthttpd to host an html web page / site?
K. Frank
2015-06-29 13:41:44 UTC
Permalink
Hello List!

I am new to Wt (and to web programming in general). I have built a
few very simple Wt applications and hosted them with wthttpd.

What is the easiest (or most practical) way to use wthttpd to serve a
single html web page? If this can't be done reasonably, what would be
the simplest way to wrap the html file (with minor tweaks, if necessary)
in a Wt application and then host it with wthttpd?

More generally, let's say that I would like my home page to be a plain
html web page that has links to Wt web pages / applications. Would
it be practical to host such a scheme with wthttpd, and, if so, what
would be the best way to do so?

(Side question: Could anyone recommend a basic, lightweight html
editor?)


Thanks.


K. Frank
Koen Deforche
2015-07-02 11:37:10 UTC
Permalink
Hey,

The wthttpd is also a simple web server, serving static files from inside
it's docroot. The simplest way to serve static contents is to put it into
the docroot.
You will need to implement a main() function to instantiate the server.
From your use-case, it sounds logical and totally sensible to host the
static pages inside the same wthttpd that also serves your dynamic content.

Koen
Hello List!
I am new to Wt (and to web programming in general). I have built a
few very simple Wt applications and hosted them with wthttpd.
What is the easiest (or most practical) way to use wthttpd to serve a
single html web page? If this can't be done reasonably, what would be
the simplest way to wrap the html file (with minor tweaks, if necessary)
in a Wt application and then host it with wthttpd?
More generally, let's say that I would like my home page to be a plain
html web page that has links to Wt web pages / applications. Would
it be practical to host such a scheme with wthttpd, and, if so, what
would be the best way to do so?
(Side question: Could anyone recommend a basic, lightweight html
editor?)
Thanks.
K. Frank
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
witty-interest mailing list
https://lists.sourceforge.net/lists/listinfo/witty-interest
K. Frank
2015-07-04 02:09:37 UTC
Permalink
Hi Koen!
Post by Koen Deforche
Hey,
The wthttpd is also a simple web server, serving static files from inside
it's docroot.
Okay, I think I have this working.

Just to confirm, is the following the minimal wthttpd server?

#include <Wt/WApplication>
#include <Wt/WEnvironment>

using namespace Wt;

WApplication *createApplication(const WEnvironment& env) {
return new WApplication (env);
}

int main (int argc, char **argv) {
return WRun (argc, argv, &createApplication);
}

Note, I do not derive from WApplication -- I just instantiate a plain
WApplication and pass it to WRun. (Of course my app has no
dynamic content, but I guess the WApplication is the wthttpd server
and the call to WRun starts it up. Is this correct?

Is this the bare-bones but "right" way to use wthttpd as a static
content web server?

I then run the server as follows:

minimal_wt_server --http-address=0.0.0.0 --http-port=80
--deploy-path=/dummy --docroot=.
Post by Koen Deforche
The simplest way to serve static contents is to put it into
the docroot.
If I then put a simple "index.html" file in the working directory of
minimal_wt_server (This should be the docroot directory.) then a
call to the url:

http://localhost/

shows the contents of index.html.

If I had set "--deploy-path=/" (rather than "--deploy-path=/dummy")
then "http://localhost/" would have shown the "blank" web page of
the "empty" WApplication app. (To see index.html I would have to
use "http://localhost/index.html".)

Is this all correct?
Post by Koen Deforche
You will need to implement a main() function to instantiate the server.
Just to confirm, main needs to call WRun with a pointer to a function
that returns a (pointer to a) WApplication object. (That is, there is not,
for example, some function call such as WApplication::start_wthttpd()
that starts an "empty" wthttpd server.) Is this correct?
Post by Koen Deforche
From your use-case, it sounds logical and totally sensible to host the
static pages inside the same wthttpd that also serves your dynamic content.
Yes, thanks. That is the general idea I am thinking of.
Post by Koen Deforche
Koen
Sorry for these naive and detailed questions, but this is all new to me.


Thanks.


K. Frank
Post by Koen Deforche
Post by K. Frank
Hello List!
I am new to Wt (and to web programming in general). I have built a
few very simple Wt applications and hosted them with wthttpd.
What is the easiest (or most practical) way to use wthttpd to serve a
single html web page? If this can't be done reasonably, what would be
the simplest way to wrap the html file (with minor tweaks, if necessary)
in a Wt application and then host it with wthttpd?
More generally, let's say that I would like my home page to be a plain
html web page that has links to Wt web pages / applications. Would
it be practical to host such a scheme with wthttpd, and, if so, what
would be the best way to do so?
(Side question: Could anyone recommend a basic, lightweight html
editor?)
Thanks.
K. Frank
Koen Deforche
2015-07-06 09:44:07 UTC
Permalink
Hey,
Post by K. Frank
Just to confirm, is the following the minimal wthttpd server?
#include <Wt/WApplication>
#include <Wt/WEnvironment>
using namespace Wt;
WApplication *createApplication(const WEnvironment& env) {
return new WApplication (env);
}
int main (int argc, char **argv) {
return WRun (argc, argv, &createApplication);
}
Note, I do not derive from WApplication -- I just instantiate a plain
WApplication and pass it to WRun. (Of course my app has no
dynamic content, but I guess the WApplication is the wthttpd server
and the call to WRun starts it up. Is this correct?
You should even be able to do like this (without a callback):

int main (int argc, char **argv) {
WServer server(argc, argv, WTHTTP_CONFIGURATION);
if (server.start()) {
WServer::waitForShutdown();
server.stop();
}

return 0;
}

But later you will have a dynamic application, so your solution might then
be better.

WRun(), or server.start(), starts the httpd server. The createApplication()
callback
is used only for the dynamic sessions -- for each session there's a call to
this callback
function.
Post by K. Frank
If I had set "--deploy-path=/" (rather than "--deploy-path=/dummy")
then "http://localhost/" would have shown the "blank" web page of
the "empty" WApplication app. (To see index.html I would have to
use "http://localhost/index.html".)
Is this all correct?
Yes.
Post by K. Frank
You will need to implement a main() function to instantiate the server.
Just to confirm, main needs to call WRun with a pointer to a function
that returns a (pointer to a) WApplication object. (That is, there is not,
for example, some function call such as WApplication::start_wthttpd()
that starts an "empty" wthttpd server.) Is this correct?
There is, see above. WRun() simply instantiates a server, configures and
starts it.

Regards,
koen
K. Frank
2015-07-06 17:04:19 UTC
Permalink
Hello Koen!

Thanks very much for your answers. Your explanation below is
very helpful.

I had been looking through the Wt documentation, but didn't come
across anything with this level of overview plus details. Is there
somewhere in the documentation I should make a point of looking?

Or is this list (plus the source code) the best way to go when I have
these kinds of questions?


Thanks again for your help.


K. Frank
Post by K. Frank
Hey,
Post by K. Frank
Just to confirm, is the following the minimal wthttpd server?
...
Note, I do not derive from WApplication -- I just instantiate a plain
WApplication and pass it to WRun. (Of course my app has no
dynamic content, but I guess the WApplication is the wthttpd server
and the call to WRun starts it up. Is this correct?
int main (int argc, char **argv) {
WServer server(argc, argv, WTHTTP_CONFIGURATION);
if (server.start()) {
WServer::waitForShutdown();
server.stop();
}
return 0;
}
But later you will have a dynamic application, so your solution might then
be better.
WRun(), or server.start(), starts the httpd server. The createApplication()
callback
is used only for the dynamic sessions -- for each session there's a call to
this callback
function.
...
Regards,
koen
Loading...