This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-09
Channels
- # announcements (23)
- # babashka (7)
- # beginners (69)
- # biff (5)
- # calva (12)
- # cider (10)
- # cljfx (9)
- # clojure (60)
- # clojure-austin (1)
- # clojure-europe (14)
- # clojure-korea (2)
- # clojure-losangeles (2)
- # clojure-madison (1)
- # clojure-nl (1)
- # clojure-norway (23)
- # clojure-uk (7)
- # clojuredesign-podcast (16)
- # clojurescript (40)
- # datomic (8)
- # gratitude (4)
- # mount (3)
- # nrepl (2)
- # off-topic (38)
- # pathom (3)
- # releases (1)
- # ring (8)
- # shadow-cljs (7)
Is it possible to configure Biff so it uses more than one base-url
? My, uh, recent success with the Wastrle game has my wife asking if I can set up her website, which would only be a handful of static pages. I figured if we could get that running on the project I currently have going, we could save some hosting costs. I've got it up on Digital Ocean and things seem okay on that end (https://docs.digitalocean.com/support/can-i-have-more-than-one-domain-on-the-same-droplet/), but I'm not sure how to pull that off in the code.
Yeah you can totally do that. Mainly you'll need to create a second handler
function and then use the website domain name to pick which handler to use for each request. Something like this, in your main namespace:
(def main-routes [["" {:middleware [mid/wrap-site-defaults]}
(keep :routes modules)]
["" {:middleware [mid/wrap-api-defaults]}
(keep :api-routes modules)]])
(def alt-routes [["" {:middleware [mid/wrap-site-defaults]}
(keep :alt-routes modules)]])
(def main-handler (-> (biff/reitit-handler {:routes main-routes})
mid/wrap-base-defaults))
(def alt-handler (-> (biff/reitit-handler {:routes alt-routes})
mid/wrap-base-defaults))
(defn handler [{:keys [server-name] :as ctx}]
(if (= server-name "")
(alt-handler ctx)
(main-handler ctx)))
Then for the second website, you would make some modules/plugins that have a :alt-routes
key instead of :routes
. Note that in development the server-name
will be "localhost"
, so when you're developing the static site you may need to edit handler
so it does e.g. (if (#{"" "localhost"} server-name) ...)
.
Other than that you'll need to set up the domain in digitalocean so it points to the droplet, same as you did for the main domain. If you want to set up an HTTPS certificate, you can SSH into the droplet and run certbot --nginx
, then when it asks for the domain(s), type in e.g. ,
.
:biff/base-url
is mainly just used to tell the authentication plugin where to have the sign-in links go. So if the second site doesn't need to handle signups, no need to change anything there. Honestly it occurs to me that even the authentication plugin could just use server-name
instead of requiring an explicit config option...Now all that being said, another good option for a static site is you can write out all the pages to html files on your local machine and then deploy them to e.g. https://www.netlify.com/ for free. That's what I do for http://biffweb.com and http://tfos.co. There is a decent amount of glue code required though, and since you're already familiar with biff development, going the netlify route would probably be more work with not much benefit. I do have another project aimed at static site development, but it's not documented yet and probably needs some more code work too before the first public release. https://github.com/borkdude/quickblog could be worth looking at though.
Wonderful! And Netlify is new to me. It's good to have options.