noir

Clojure / Noir: Force HTTPS, redirect if the request was http:// to https://

℡╲_俬逩灬. 提交于 2019-12-05 04:02:44
I'm trying to force SSL on my site. I want to have a ring style middle-ware to redirect the site to the same URL with https if it is only http I wrote the following code but it doesn't really do anything besides check the request scheme and print the URL it should be redirecting to. (defn https-url [request-url] (str (str (str (str "https://" (:server-name request-url) ":") (:server-port request-url))) (:uri request-url))) (defn require-https [handler] (fn [request] (let [page-request (handler request)] (if (= (:scheme page-request) :http) (println (https-url page-request)))))) (server/add

noir vs compojure?

你说的曾经没有我的故事 提交于 2019-12-04 09:01:29
问题 I'm having trouble understanding the point of clojure's Noir library. It seems to be a framework written on top of compojure that renames defroute to defpage and calls it a day. Obviously an unfair simplification, but what exactly does Noir bring to the table? Why would I use Noir instead of plain compojure+hiccup? EDIT/UPDATE: Noir is deprecated, interesting write up here: http://blog.raynes.me/blog/2012/12/13/moving-away-from-noir/. 回答1: Compojure is a small framework that generates Ring

Reason for skipping AOT?

偶尔善良 提交于 2019-12-03 10:43:04
问题 In many noir apps I have seen the below declaration. What is the purpose of skipping aot ? When to use it and when not to use it ? Any advantages / disadvantages ? :main ^{:skip-aot true} sample-app.server 回答1: This isn't specific to noir but one scenario you might want to skip AOT for a given namespace is when deploying your code to a PaaS provider such as heroku. Heroku performs AOT compilation of your code by default so consider this snippet in your server.clj: (db/connect! (System/getenv

Reason for skipping AOT?

房东的猫 提交于 2019-12-03 01:11:16
In many noir apps I have seen the below declaration. What is the purpose of skipping aot ? When to use it and when not to use it ? Any advantages / disadvantages ? :main ^{:skip-aot true} sample-app.server This isn't specific to noir but one scenario you might want to skip AOT for a given namespace is when deploying your code to a PaaS provider such as heroku. Heroku performs AOT compilation of your code by default so consider this snippet in your server.clj: (db/connect! (System/getenv "DB_URL")) (defn start [port] (run-jetty app {:port port :join? false :max-threads 100})) In principle this

How to do HTTP 302 redirects with Noir Web framework

老子叫甜甜 提交于 2019-12-01 04:44:47
I'm helping to set up a Web site with Clojure's Noir framework, though I have a lot more experience with Django/Python. In Django, I'm used to URLs such as http://site/some/url being 302-redirected automagically to http://site/some/url/ Noir is more picky and does not do this. What would be the proper way to do this automatically? Since good URLs are an important way of addressing into a site, and many users will forget the trailing slash, this is basic functionality I'd like to add to my site. EDIT: Here is what finally worked for me, based on @IvanKoblik's suggestions: (defn wrap-slash

Variable passed to macro gets resolved in wrong namespace?

笑着哭i 提交于 2019-12-01 04:17:18
The Noir macro defpage is giving me a little bit of trouble. I am trying to construct a call similar to this: (defpage [:post "some/url"] [data] ;; some stuff... ) However, instead of using the keyword :post I would like to use a variable, like this: (def my-method :post) (defpage [my-method "some/url"] [data] ;; some stuff... ) The problem is that when the macro expands, it wants to resolve the variable my-method in the compojure.core namespace instead of my own, giving me the error: No such var: compojure.core/MY-METHOD How can I force my-method to resolve in the current context? Michiel