Skip to content

Commit

Permalink
Fix serving of service worker by reusing serve-file
Browse files Browse the repository at this point in the history
Otherwise content-type isn't set correct and it won't work
  • Loading branch information
mk committed Sep 11, 2023
1 parent 49aeb6b commit d64677d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/nextjournal/clerk/view.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
[:script {:type "text/javascript"}
"if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/service_worker.js')
.register('/clerk_service_worker.js')
.then(function() { console.log('Service Worker: Registered') })
.catch(function(error) { console.log('Service Worker: Error', error) })
}"])
Expand Down
9 changes: 1 addition & 8 deletions src/nextjournal/clerk/webserver.clj
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@

#_(serve-file "public" {:uri "/js/viewer.js"})

(defn serve-resource [resource-name]
(if-some [r (io/resource resource-name)]
{:status 200 :body (slurp r)}
{:status 404}))

#_(serve-resource "stylesheets/viewer.css")
#_(serve-resource "service_worker.js")

(defn sync-atom-changed [key atom old-state new-state]
(eval '(nextjournal.clerk/recompute!)))
Expand Down Expand Up @@ -260,7 +253,7 @@
(case (get (re-matches #"/([^/]*).*" uri) 1)
"_blob" (serve-blob @!doc (extract-blob-opts req))
("build" "js" "css") (serve-file uri (str "public" uri))
"service_worker.js" (serve-resource "js/service_worker.js")
"clerk_service_worker.js" (serve-file uri (fs/path (io/resource "public/clerk_service_worker.js")))
("_fs") (serve-file uri (str/replace uri "/_fs/" ""))
"_ws" {:status 200 :body "upgrading..."}
"favicon.ico" {:status 404}
Expand Down

0 comments on commit d64677d

Please sign in to comment.