comparison website/src/tutorial.html.luan @ 495:598123096772

rename service() to respond()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 15 May 2015 18:10:14 -0600
parents 2b9bc97f0439
children 92c3d22745b8
comparison
equal deleted inserted replaced
494:2b9bc97f0439 495:598123096772
2 local Html = require "luan:Html" 2 local Html = require "luan:Html"
3 local Http = require "luan:http/Http" 3 local Http = require "luan:http/Http"
4 local Shared = require "site:/Shared" 4 local Shared = require "site:/Shared"
5 5
6 6
7 function service() 7 function respond()
8 Io.stdout = Http.response.text_writer() 8 Io.stdout = Http.response.text_writer()
9 %> 9 %>
10 <html> 10 <html>
11 <head> 11 <head>
12 <% Html.simply_html_head() %> 12 <% Html.simply_html_head() %>
72 72
73 <p><tt><pre><%=Html.encode[[ 73 <p><tt><pre><%=Html.encode[[
74 local Io = require "luan:Io" 74 local Io = require "luan:Io"
75 local Http = require "luan:http/Http" 75 local Http = require "luan:http/Http"
76 76
77 function service() 77 function respond()
78 Io.stdout = Http.response.text_writer() 78 Io.stdout = Http.response.text_writer()
79 %> 79 %>
80 <html> 80 <html>
81 <body> 81 <body>
82 Hello World 82 Hello World
86 end 86 end
87 ]]%></pre></tt></p> 87 ]]%></pre></tt></p>
88 88
89 <p>Now go back to the parent directory and do <b>luan luan:http/serve file:site</b>. This will run the Luan web server on port 8080. Try going to <a href="http://localhost:8080/">http://localhost:8080/</a>. You should see the directory. If you click on <b>hi.luan</b> you will see the source. But if you remove the <b>.luan</b> and just go to <a href="http://localhost:8080/hi">http://localhost:8080/hi</a> then you will run the program which will generate the web page.</p> 89 <p>Now go back to the parent directory and do <b>luan luan:http/serve file:site</b>. This will run the Luan web server on port 8080. Try going to <a href="http://localhost:8080/">http://localhost:8080/</a>. You should see the directory. If you click on <b>hi.luan</b> you will see the source. But if you remove the <b>.luan</b> and just go to <a href="http://localhost:8080/hi">http://localhost:8080/hi</a> then you will run the program which will generate the web page.</p>
90 90
91 <p>The Luan webserver looks for function named <b>service</b> in the file and calls it to generate the page. Code of the form <b><%=Html.encode[[%>...<%]]%></b> writes its output to <b>Io.stdout</b> which by default is the standard output of the command line. So in <b>service</b> one usually starts by setting <b>Io.stdout</b> to a <tt>text_writer</tt> which writes its output to the HTTP response (to the web browser).</p> 91 <p>The Luan webserver looks for function named <b>respond</b> in the file and calls it to generate the page. Code of the form <b><%=Html.encode[[%>...<%]]%></b> writes its output to <b>Io.stdout</b> which by default is the standard output of the command line. So in <b>respond</b> one usually starts by setting <b>Io.stdout</b> to a <tt>text_writer</tt> which writes its output to the HTTP response (to the web browser).</p>
92 92
93 <p>You can find this example and others in the <a href="examples">examples directory</a>. Take a look at <a href="examples/hi2.luan">hi2.luan</a> next. Remember to remove the <b>.luan</b> from the URL to run the code. And by the way, you can see the source for this page at <a href="tutorial.html.luan">tutorial.html.luan</a>.</p> 93 <p>You can find this example and others in the <a href="examples">examples directory</a>. Take a look at <a href="examples/hi2.luan">hi2.luan</a> next. Remember to remove the <b>.luan</b> from the URL to run the code. And by the way, you can see the source for this page at <a href="tutorial.html.luan">tutorial.html.luan</a>.</p>
94 94
95 <p>So now you have built your website and you want to publish it to the web. If you have your own domain, create a CNAME record for it pointing to <b>s1.luanhost.com</b>. If you don't have a domain, just use a domain like <b>bob.s1.luanhost.com</b> (anything of the form <b>*.s1.luanhost.com</b>). Assuming your directory is <b>site</b> and you will use the password <b>secret</b>, do the following from the command line: 95 <p>So now you have built your website and you want to publish it to the web. If you have your own domain, create a CNAME record for it pointing to <b>s1.luanhost.com</b>. If you don't have a domain, just use a domain like <b>bob.s1.luanhost.com</b> (anything of the form <b>*.s1.luanhost.com</b>). Assuming your directory is <b>site</b> and you will use the password <b>secret</b>, do the following from the command line:
96 96