diff --git a/lib/route.rb b/lib/route.rb
index b2ee72e..1841f9a 100644
--- a/lib/route.rb
+++ b/lib/route.rb
@@ -19,7 +19,8 @@ class Router
if match != nil
print("\nMatch: ", match, "\n")
- return 200
+ returner = [match, 200]
+ return returner
else
if request.resource.match?(@routes[0][:resource]) != true
p "failed to find: #{request.resource} resource.\nExpected: #{String(@routes[0][:resource])} resource"
@@ -28,7 +29,8 @@ class Router
else
p "Failed to match, got no reason, just kinda didn't feel like it"
end
- return 404
+ returner = [request, 404]
+ return returner
end
end
diff --git a/lib/tcp_server.rb b/lib/tcp_server.rb
index ba61e87..e34267c 100644
--- a/lib/tcp_server.rb
+++ b/lib/tcp_server.rb
@@ -14,7 +14,18 @@ class HTTPServer
router = Router.new
router.add_route("GET",/\/grillkorv\/\d/) do |id, senap|
- puts "woot #{senap}"
+ if File.read("./public/grillkorv.html") != nil
+ File.read("./public/grillkorv.html")
+ else
+ "Html not found"
+ end
+ end
+ router.add_route("GET",/\/grillkorv\/\w.css/) do |id, senap|
+ if File.read("./public/grillkorv.html") != nil
+ File.read("./public/grillkorv.html")
+ else
+ "Html not found"
+ end
end
router.add_route("GET","/favicon.ico")
@@ -32,25 +43,37 @@ class HTTPServer
pp request
routeReturn = router.match_route(request)
- if routeReturn == 200
- html = "
Hello, World!
"
- status = 200
- elsif routeReturn == 404
- html = "Not found!
"
- status = 404
+ outputContent = {}
+ if routeReturn[1] == 200
+ if routeReturn[0][:block] != nil
+ outputContent[:info] = routeReturn[0][:block].call
+ print("Recieved HTML, enabling as called:\n #{outputContent[:info]}")
+ outputContent[:type] = "text/html"
+ status = 200
+ else
+ outputContent[:info] = nil
+ status = 200
+ end
+ elsif routeReturn[1] == 404
+ print("HTML route not found, searching for target file...\n")
+ if File.file?("./public/#{routeReturn[0].resource}")
+ outputContent[:info] = File.read("./public#{routeReturn[0].resource}")
+ print("Successfully opened file \"./public#{routeReturn[0].resource}\" with contents:\n#{outputContent[:info]}\n ")
+ outputContent[:type] = "text/css"
+ status = 200
+ else
+ print("Could not find file: \"./public/#{routeReturn[0].resource}\"\n")
+ status = 404
+ end
end
-
-
-
- #Sen kolla om resursen (filen finns)
-
-
+
# Nedanstående bör göras i er Response-klass
session.print "HTTP/1.1 #{status}\r\n"
- session.print "Content-Type: text/html\r\n"
+ session.print "Content-Type: #{outputContent[:type]}\r\n"
+ print("Reading content type: #{outputContent[:type]}\n")
session.print "\r\n"
- session.print html
+ if outputContent[:info]; session.print outputContent[:info] end
session.close
end
end
diff --git a/public/css/style.css b/public/css/style.css
new file mode 100644
index 0000000..95a11ca
--- /dev/null
+++ b/public/css/style.css
@@ -0,0 +1,4 @@
+li {
+ color: green;
+ background-color: blueviolet;
+}
\ No newline at end of file
diff --git a/public/grillkorv.html b/public/grillkorv.html
new file mode 100644
index 0000000..b19fa95
--- /dev/null
+++ b/public/grillkorv.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+ HOTDAWGGGG
+
+
+
+ - This is the best
+ WEBSITE YOU HAVE EVER SEEEN
+ Cuz we got hotdogs :D
+
+
+
\ No newline at end of file