Dynamicly generated websites in Erlang
Torbjorn Tornkvist
tobbe@REDACTED
Tue Mar 27 08:57:28 CEST 2001
> I've been told that I could use some of the code in bluetail's ticket
> tracker, but from a quick look at it I think I'd much rather use other
> (easier hopefully) options, if there are any.
Don't let the amount of code scare you. It is rather easy
to get going with INETS. Just copy the example server root
directory from the standard Erlang/OTP application, e.g:
cp -R /usr/local/usr_lib/erlang/lib/inets-2.5.3/examples/server_root xxx
Modify the xxx/conf/httpd.conf file.
Especially the directive where you state your Erlang module to be called:
ErlScriptAlias /my my
Create a file: xxx/inets.config which points out the conf file above:
cat > xxx/inets.config
[{inets,
[{services,
[{httpd,"/....../xxx/conf/httpd.conf"}]}]}].
^D
Start Erlang with the switches: -config /...../xxx/inets -s my
In your startup code in my.erl, call: application:start(inets)
Now when you point a Web browser towards:
http://something:aport/my/my/test
The function: my:test/2 should be called by INETS,
and whatever it returns is sent back to the web browser.
Example (my.erl):
test(Env,Input) ->
InData = httpd:parse_query(Input),
io:format("GOT THIS: ~p~n",[InData]),
%% Returning this
["<HTML>",
"<HEAD>",
"<TITLE> A Test Page </TITLE>",
"</HEAD>",
"<BODY>",
"<H1> A TEST </H1>",
"</BODY>",
"</HTML>"].
For creating HTML content, the faqoff/html_lib.erl
module in the BTT package can be useful.
Good luck ! /Tobbe
--
--
Torbjörn Törnkvist , tel: +46 8 545 55 023 , fax: +46 8 654 70 71
Alteon Web Systems , St.Eriksgatan 44 , SE-112 34 Stockholm , Sweden
Email: ttornkvist@REDACTED , Web: http://www.alteon.com
More information about the erlang-questions
mailing list