Serve index.html at / by default in Compojure

An alternative could be to create either a redirect or a direct response in an additional route. Like so:

(ns compj-test.core
  (:use [compojure.core])
  (:require [compojure.route :as route]
            [ring.util.response :as resp]))

(defroutes main-routes
  (GET "https://stackoverflow.com/" [] (resp/file-response "index.html" {:root "public"}))
  (GET "/a" [] (resp/resource-response "index.html" {:root "public"}))
  (route/resources "https://stackoverflow.com/")
  (route/not-found "Page not found"))

The “https://stackoverflow.com/” route returns a file response of “index.html” which is present in the public folder. The “/a” route responds directly by ‘inlineing’ the file index.html.

More on ring responses: https://github.com/mmcgrana/ring/wiki/Creating-responses

EDIT: removed unnecessary [ring.adapter.jetty] import.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)