ring

Passing state as parameter to a ring handler?

余生颓废 提交于 2019-12-30 04:01:07
问题 How does one inject state into ring handlers most conveniently (without using global vars)? Here is an example: (defroutes main-routes (GET "/api/fu" [] (rest-of-the-app the-state))) (def app (-> (handler/api main-routes))) I would like to get the-state into the compojure handler for main-routes . The state might be something like a map created with: (defn create-app-state [] {:db (connect-to-db) :log (create-log)}) In a non ring application I would create the state in a main function and

Inspect state atom which gets updated by a ring handler

混江龙づ霸主 提交于 2019-12-24 16:00:41
问题 Consider the following scenario: A minimal boot task starts up a http server: (boot (serve :handler 'myapp.server/handler :port 3000)) (This might be launched in several ways, here it's ok to just run it from a nrepl session, e.g. started by boot repl from the terminal) The handler is represented by the function handler inside the namespace myapp.server . The corresponding file looks like this: (ns myapp.server (:require ...)) (defonce server-state (atom {:nr 0})) (defn handler [req] (prn

Compojure app not playing well with with-redefs

丶灬走出姿态 提交于 2019-12-24 00:28:45
问题 I'm writing a Compojure application and am using clj-webdriver to graphically test it. I'm trying to use with-redefs to mock out the function that pulls out data from persistence to just return canned values, but it's ignoring my function overwrite. I know with-redefs works in terms of vars, but it's still not working: project.clj relevant pieces: (defproject run-hub "0.1.0-SNAPSHOT" :main run-hub.handler/start-server) handler.clj: (ns run-hub.handler (:require [compojure.core :refer :all]

Compojure: access filesystem

丶灬走出姿态 提交于 2019-12-22 10:30:03
问题 this is my project.clj file: (defproject org.github.pistacchio.deviantchecker "0.9.0" :description "A one page application for keeping track of changes on deviantart.com gallieries" :dependencies [[org.clojure/clojure "1.2.1"] [org.clojure/clojure-contrib "1.2.0"] [enlive "1.0.0"] [compojure "0.6.4"] [ring/ring-jetty-adapter "1.0.0-beta2"]] :dev-dependencies [[lein-ring "0.4.6"]] :ring {:handler org.github.pistacchio.deviantchecker.core/app} :main org.github.pistacchio.deviantchecker.core)

How to serve the stream pdf with ring

╄→尐↘猪︶ㄣ 提交于 2019-12-22 04:49:14
问题 I'm trying to serve a clj-http generated document directly via ring/compojure. I thought ring.util/piped-output-stream would work, but it seems I'm not understanding something here... This: (defn laminat-pdf-t [natno] (piped-input-stream (fn [output-stream]) (pdf [ {:title (str "Omanimali-Kuscheltierpass" natno) :orientation :landscape :size :a6 :author "Omanimali - Stefanie Tuschen" :register-system-fonts true } ;; [:svg {} (clojure.java.io/file ;; (str "/einbuergern/" natno "/svg" ))] [

设置不可写目录阻止webshell

家住魔仙堡 提交于 2019-12-22 01:03:40
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我是研究防御方向的,所以很多时候看的搞攻击的出身做防御产品觉得有点悲哀,想的产品设计完全不贴合实际。 作为反感的就是做皮毛功夫,以及拿一句“甲方需求多种多样”敷衍人。 看看老前辈教教你老一辈黑产们是怎么抵御webshell的 http://www.xoslab.com/ 打开这个网站,下载一个装好 按照下面的图,锁定phpstudy的目录设置可读不可写,然后点红框的按钮启动! 这个工具是内核级的,不论是手工还是ring3程序写文件都会失败 Linux上面怎么搞,好好去学学selinux :-) 原创来自于:https://my.oschina.net/9199771/blog/3145572 来源: oschina 链接: https://my.oschina.net/9199771/blog/3145572

Compojure routes with different middleware

北战南征 提交于 2019-12-20 08:27:58
问题 I'm currently writing an API in Clojure using Compojure (and Ring and associated middleware). I'm trying to apply different authentication code depending on the route. Consider the following code: (defroutes public-routes (GET "/public-endpoint" [] ("PUBLIC ENDPOINT"))) (defroutes user-routes (GET "/user-endpoint1" [] ("USER ENDPOINT 1")) (GET "/user-endpoint2" [] ("USER ENDPOINT 1"))) (defroutes admin-routes (GET "/admin-endpoint" [] ("ADMIN ENDPOINT"))) (def app (handler/api (routes public

File is downloaded instead of being displayed in the browser

你。 提交于 2019-12-20 05:19:16
问题 I have created a brand new app from the luminus app template using lein new luminus my-app +postgres +auth +cljs +swagger . In the generated file src/clj/my_app/routes/home.clj the following compojure route is created: (GET "/docs" [] (response/ok (-> "docs/docs.md" io/resource slurp))) When I try to access localhost:3000/docs the file is simply downloaded instead of displayed in the browser. It happens both with Chrome and Safari. It seems related to ring.util.http-response/ok since I can

Friend authentication empty param

北城以北 提交于 2019-12-13 03:36:49
问题 I am trying to implement friend authentication on my web app but when i try to login i get this */login?&login_failed=Y&username=*...my param is empty and i cant login,what am i doing wrong? these are my routes... (defroutes routes (GET "/" [] (index)) (GET "/indexMessage" [] (indexMessage)) (GET "/login" req (index)) (POST "/insert-user" {params :params} (let [firstname (get params "firstname") lastname (get params "lastname") email (get params "email") password (get params "password") sex

How can I conditionally load functionality in a clojure web-app

六眼飞鱼酱① 提交于 2019-12-12 06:17:15
问题 I have a clojure web app (standard ring handlers and compojure routes on a jetty server) for which I enabled live asset recompilation as middleware, which has been very very handy in development. As we get closer to production I would like to find a way not to load that code in production and instead read the pre-compiled assets (which I am able to generate as a lein task). Currently the asset compilation machinery lives in the project code - it can be loaded from the lein task using eval-in