diff --git a/resources/public/favicon.ico b/resources/public/favicon-fallback.ico similarity index 100% rename from resources/public/favicon.ico rename to resources/public/favicon-fallback.ico diff --git a/src/clj/bluegenes/index.clj b/src/clj/bluegenes/index.clj index b739f8533..0594b6e56 100644 --- a/src/clj/bluegenes/index.clj +++ b/src/clj/bluegenes/index.clj @@ -87,7 +87,8 @@ "null") ";")] ; Javascript: - [:link {:rel "shortcut icon" :href "https://raw.githubusercontent.com/intermine/design-materials/f5f00be4/logos/intermine/fav32x32.png" :type "image/png"}] + ;; This favicon is dynamically served; see routes.clj. + [:link {:href "/favicon.ico" :type "image/x-icon" :rel "shortcut icon"}] [:script {:src "https://cdn.intermine.org/js/intermine/imjs/latest/im.min.js"}] [:script {:crossorigin "anonymous" :integrity "sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" diff --git a/src/clj/bluegenes/routes.clj b/src/clj/bluegenes/routes.clj index 6b78fe76d..50e75fde2 100644 --- a/src/clj/bluegenes/routes.clj +++ b/src/clj/bluegenes/routes.clj @@ -2,13 +2,15 @@ (:require [compojure.core :as compojure :refer [GET defroutes context]] [compojure.route :refer [resources]] [ring.util.response :as response :refer [response]] + [ring.util.http-response :refer [found]] [bluegenes.ws.auth :as auth] [bluegenes.ws.ids :as ids] [bluegenes.ws.rss :as rss] [bluegenes.ws.lookup :as lookup] [bluegenes.index :refer [index]] [config.core :refer [env]] - [bluegenes.utils :refer [env->mines]])) + [bluegenes.utils :refer [env->mines]] + [clj-http.client :as client])) (defn with-init "One of BlueGenes' web service could have added some data we want passed on @@ -22,12 +24,30 @@ (response/charset "utf-8") (assoc :session (dissoc session :init)))) +(defn get-favicon + "Get a favicon for when one isn't configured." + [] + (let [mine-favicon (str (:bluegenes-default-service-root env) "/model/images/favicon.ico")] + (if (-> (client/get mine-favicon) + (get-in [:headers "Content-Type"]) + (= "image/x-icon")) + (found mine-favicon) + (found "/favicon-fallback.ico")))) + ; Define the top level URL routes for the server (def routes - (compojure/let-routes [mines (env->mines env)] + (compojure/let-routes [mines (env->mines env) + favicon* (delay (get-favicon))] ;;serve compiled files, i.e. js, css, from the resources folder (resources "/") + ;; The favicon is chosen from the following order of priority: + ;; 1. `public/favicon.ico` being present as a resource (admin will have to add this). + ;; 2. `//model/images/favicon.ico` being present on the default mine. + ;; 3. `public/favicon-fallback.ico` which is always present. + ;; Hence it follows that the following route won't be matched if [1] is true. + (GET "/favicon.ico" [] @favicon*) + (GET "/version" [] (response {:version "0.1.0"})) ;; Anything within this context is the API web service.