master
E. Almqvist 3 years ago
parent 0f013a6558
commit fb64476b31
  1. 36
      wesweb01/webbserver_test/app.rb
  2. 3
      wesweb01/webbserver_test/public/test.html

@ -0,0 +1,36 @@
#!/usr/bin/ruby
require "sinatra"
def read_page(page)
begin
content = File.read("public/#{page}.html")
return content
rescue Exception => err
return ":("
end
end
get("/") do
return "Hello world!"
end
get("/page/:page") do
page = params[:page]
page = page.gsub(".", "")
content = read_page(page).gsub("$TITLE", page.upcase())
return content
end
get("/fruits") do
fruits = %w(Apple Orange Banana Grillkorv Varmkorv Frukt Hej)
listitems = ""
fruits.each do |fruit|
listitems += "<li>#{fruit}</li>"
end
response = "<ul>#{listitems}</ul>"
return response
end

@ -0,0 +1,3 @@
<h1> Hej jag är en hemsida </h1>
<p>Texta hiodfhsdiof hiosdhf iosdhfiosdhiof</p>
<h2>$TITLE</h2>
Loading…
Cancel
Save