 (defn ensure-secure [request]
 	(= :https (:scheme request)))
 
+(defn render-html-posts-helper [blogid request]
+	(render-html-posts
+		(data/get-posts blogid 10 0)
+		(util/uri-from-request request)
+		(:title (data/get-blog blogid))
+		blogid))
 
 
 (defroutes main-routes
-	(GET "/" [] (index-page))
+	(GET "/" [:as request]
+		(let [server-name (str
+						(:server-name request)
+						(if (not (nil? (:server-port request)))
+							(str ":" (:server-port request))))
+				uri (:uri request)]
+			(let [domain (data/get-domain server-name)]
+				(if (not (nil? domain))
+					(render-html-posts-helper (:blogid domain) request)
+					(index-page)))))
 
 	; "account urls"
 	(GET templates/*permission-denied-uri* [] (permission-denied))

		(wrap-params)
		(wrap-json-params)))

(defn -main []
	(let [port (System/getenv "PORT")
			port (if (nil? port) "3000" port)
			port (Integer/parseInt port)
			ssl-port templates/*https-port*]
		(jetty/run-jetty (app port ssl-port)
				{:port port :ssl-port ssl-port
						:keystore "devonly.keystore" :key-password "foobar"})))

	

	; "post urls"
	(GET "/blog/:blogid/post/" [blogid :as request]
		(render-html-posts-helper (Integer/parseInt blogid) request))
	(GET "/blog/:bid/post/new" [bid]
		(if (not (data/blog-owner? bid))
			(redirect templates/*permission-denied-uri*)
