Skip to content

Commit

Permalink
Support specifying a favicon, either from default mine or by adding one
Browse files Browse the repository at this point in the history
  • Loading branch information
heralden committed Apr 27, 2021
1 parent 417ea23 commit 251525c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion src/clj/bluegenes/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down
24 changes: 22 additions & 2 deletions src/clj/bluegenes/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. `/<mine>/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.
Expand Down

0 comments on commit 251525c

Please sign in to comment.