Fork me on GitHub
#biff
<
2023-02-17
>
Illyria13:02:17

Hi, how do I get Jetty to read a XML file? I read that Jetty needs jetty-ant-config.xml in order to do URL rewriting, but I'm confuse as how to accomplish this with an embedded Jetty server.

Jacob O'Bryant18:02:21

Hm, I'm not familiar with configuring Jetty via XML. But if needed, you can modify the way Jetty starts in Biff by copying https://github.com/jacobobryant/biff/blob/master/src/com/biffweb/impl/misc.clj#L63 into your project, edit as necessary, and use that instead of https://github.com/jacobobryant/biff/blob/master/example/src/com/example.clj#L46. Based on https://github.com/weavejester/lein-ring/issues/17, it looks like the official ring jetty adapter supports a web.xml file. Biff uses https://github.com/sunng87/ring-jetty9-adapter since it comes with bindings for websockets; not sure if that one supports using an xml file easily or not.

Jacob O'Bryant18:02:22

Let me know if it would help to replace ring-jetty9-adapter with the official ring adapter--that would be pretty straightforward as well (as long as you're not using websockets), but it'd be made a little easier if I make a couple changes to Biff.

Illyria11:02:16

@U7YNGKDHA Hmm yes, I saw that issue but too be honest I didn't really understand most of it 😅. Do you know an easier way to do URL rewriting in development (could be with something apart from Jetty)? I know you can configure it on nginx for production but I'm not sure how suitable that can be. I'm new to web development.

Illyria11:02:48

Anyways this is what I did, but I can't seem to get the hello-world function to log my message (it should run when the server starts https://ring-clojure.github.io/ring/ring.adapter.jetty.html) biffweb.clj

(defn use-jetty
  "A Biff component that starts a Jetty web server."
  [{:biff/keys [host port configurator handler]
    :or {host "localhost"
         port 8080
         configurator #'hello-world}
    :as sys}]
  (misc/use-jetty sys)
config.edn
:dev {:merge [:prod]
       :biff.elham/enable-beholder true
       :biff/host "0.0.0.0"
       :biff/port 4444
       :biff/configurator  ;<--- added this
       :biff/base-url ""
       :biff.xtdb/topology :standalone
       :biff.middleware/secure false
blog.clj
(defn hello-world [sys]
  (while true (log/info "Is this working!!!!!"))