Share your thoughts in the 2024 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

$ cat deps.edn
{:deps {org.clojure/clojure {:mvn/version "1.9.0-RC2"}
        org.clojure/clojurescript {:mvn/version "1.9.946"}}
$ touch hello.xml
$ clojure -m cljs.browser.repl &
$ curl localhost:9000/hello.xml
<html><body><h2>Page not found</h2>No page /hello.xml found on this server.</body></html>


Adding an entry to cljs.repl.browser/ext->mime-type superficially fixes that.

1) Currently used MIME type identification is very simplistic and doesn't return correct MIME types for most files. Instead, this should be delegated to the host:


(ns cljs.repl.browser
  (:import [java.nio.file Files Paths]))

(defn get-content-type [path]
  (Files/probeContentType (Paths/get path (into-array String []))))


2) Since both files and sockets are abstractions over bytes, cljs.repl.server/send-and-close should be agnostic to file encoding and just send whatever is in the file. Currently this is handled via cljs.repl.browser/mime-type->encoding.

I will prepare a patch by tomorrow.

9 Answers

0 votes
by

Comment made by: yegortimoshenko

I disagree with this being a minor defect. Currently most files are not served by the built-in HTTP server, which means that it's impossible to develop an application that has files other than HTML/CSS/JS.

0 votes
by

Comment made by: dnolen

The builtin webserver is not an important component of ClojureScript. It exists to aid tutorials.

0 votes
by

Comment made by: yegortimoshenko

I like it much more than figwheel because it's simpler, and it seems to be feature-complete other than this bug. Also, this is the first in-browser REPL that comes to mind when using new clojure tooling.

Also, previous version of this patch didn't correctly count Content-Length, changed arity of send-and-close function, and didn't work for favicons. I'm attaching a new patch that this time should be complete and cause zero breakage.

New patch is called 0001-CLJS-2433-use-JVM-to-deduce-MIME-type-send-files-via.patch in the attachments above. Link: https://dev.clojure.org/jira/secure/attachment/17586/0001-CLJS-2433-use-JVM-to-deduce-MIME-type-send-files-via.patch

Here's a GitHub link (for code review/explanations): https://github.com/hackberryhike/clojurescript/commit/ea8336da3a779cb5982875d243dc6d40abd0d3ba

0 votes
by

Comment made by: yegortimoshenko

Also, if you don't like something about this patch, do tell me and I'll fix it right away. I'm very interested in getting this merged.

0 votes
by

Comment made by: ncg

Allow me to make a case for this as well. Although somewhat of an edge case, I spent quite some
time today figuring out why cljs.main -s wouldn't serve my WebAssembly file, when everything else worked perfectly.
Especially considering the great experience provided by the new clj tooling, having to use a separate
server for one-off experiments is somewhat annoying.

0 votes
by

Comment made by: dnolen

Can we get a rebased patch?

0 votes
by

Comment made by: yegortimoshenko

Sure, will do by Monday.

0 votes
by

Comment made by: ncg

Thank you. Please let me know if I can be of assistance.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2433 (reported by yegortimoshenko)
...