ring

How do I stop jetty server in clojure?

…衆ロ難τιáo~ 提交于 2019-12-03 01:02:41
问题 I am writing a web application using ring and clojure. I am using the jetty adapter for the development server and emacs/SLIME for IDE. While wrap-reload does help, run-jetty blocks my slime session and I would like to be able to start/stop it at will without having to run it in a separate terminal session. Ideally, I would like to define a server agent and functions start-server and stop-server that would start/stop the server inside the agent. Is this possible? 回答1: I usually have a line in

New compojure template fails to start “No reader function for tag namespace”

假如想象 提交于 2019-12-02 17:53:28
问题 I'm attempting to run the boilerplate project from lein new compojure clojure-lice . When I run lein ring server I receive the following lovely error: Exception in thread "main" java.lang.RuntimeException: No reader function for tag namespace My project.clj (defproject clojure-lice "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :min-lein-version "2.0.0" :dependencies [[org.clojure/clojure "1.8.0"] [compojure "1.5.1"] [ring/ring-defaults "0.2.1"]]

Compojure routes with different middleware

旧时模样 提交于 2019-12-02 17:16:49
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-routes (-> user-routes (wrap-basic-authentication user-auth?))))) (-> admin-routes (wrap-basic

Can I make a fully non-blocking backend application with http-kit and core.async?

99封情书 提交于 2019-12-02 15:09:46
I'm wondering if it's possible to put together a fully non-blocking Clojure backend web application with http-kit. (Actually any Ring-compatible http server would be fine by me; I'm mentioning http-kit because it claims to have an event-driven, non-blocking model). EDIT: TL;DR This question is a symptom of some misconceptions I had about the nature of non-blocking/asynchronous/event-driven systems. In case you're in the same place as I was, here are some clarifications. Making an event-driven system with the performance benefits of it being non-blocking (like in Node.js) is possible only if

How do I stop jetty server in clojure?

痞子三分冷 提交于 2019-12-02 14:21:54
I am writing a web application using ring and clojure. I am using the jetty adapter for the development server and emacs/SLIME for IDE. While wrap-reload does help, run-jetty blocks my slime session and I would like to be able to start/stop it at will without having to run it in a separate terminal session. Ideally, I would like to define a server agent and functions start-server and stop-server that would start/stop the server inside the agent. Is this possible? I usually have a line in my Ring app that looks like the following: (defonce server (run-jetty #'my-app {:port 8080 :join? false}))

New compojure template fails to start “No reader function for tag namespace”

删除回忆录丶 提交于 2019-12-02 08:42:40
I'm attempting to run the boilerplate project from lein new compojure clojure-lice . When I run lein ring server I receive the following lovely error: Exception in thread "main" java.lang.RuntimeException: No reader function for tag namespace My project.clj (defproject clojure-lice "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :min-lein-version "2.0.0" :dependencies [[org.clojure/clojure "1.8.0"] [compojure "1.5.1"] [ring/ring-defaults "0.2.1"]] :plugins [[lein-ring "0.9.7"]] :ring {:handler clojure-lice.handler/app} :profiles {:dev {:dependencies [

How do you enable https and http->https redirects in ring / compojure

五迷三道 提交于 2019-12-01 03:17:43
问题 I am developing a RESTful app, for which I need to redirect requests coming in from an http address to it's https equivalent. I cannot seem to be able to enable https using ring/compojure. Anyone have some useful tutorials and/or links? I haven't found any. The documentation doesn't have anything useful either. 回答1: Its very simple. If you want to enable HTTPS support in your web app, just do the following: Generate a Java KeyStore(.jks) file using a linux tool called keytool. In the ring map

在ring0调用Ring3的代码

只愿长相守 提交于 2019-11-30 19:18:35
作者:VXK/CVC.GB 时间:2005-02-05 每次上driverdevelop总看到有人问怎么在Ring0下调用Ring3的代码—— Ring3使用Ring0已经是地球人全知道的事情了,但是ring0下使用ring3的代码 恐怕很少有人知道,Ratter和Benny这两个高人以及Elzc的作者Elzcor各自提出 过一种方法。总结起来就是三种方法,Zombie在2004年也提出过一个方法看起 来像是Ratter和Elzcor的方法结合而成~ 当然说其本质都是一种思想把ring3代码搞到ring3的空间去执行,听起来 大家也好像有所明白了吧,Benny的方法是在Ring0的向Ring3进程插入代码执行, Ratter则是Hook KAPIZ等待用户层调用发生把ring3代码放回Ring3空间,利用 KeUserModeCallBack来执行,Elzcor则是自己建立一个进程把代码内存感染到 进程执行。Zombie取两家之长搞的~。 今天我来向大家介绍的更像是Ratter和Benny的方法结合,对于Benny的方法, 我不完全采用,我采用的思想仍然是代码放回Ring3空间~ 首先无论如何我们都要有一个进程~ 习习~Windows提供强大的kernel函数帮我们虐待用户~

How to run an arbitrary startup function in a ring project?

淺唱寂寞╮ 提交于 2019-11-30 17:41:59
I've got a compojure/ring application I currently run with lein ring server that I'd like to compile to a .war so I can deploy it. I've got a definition, however, just like (def foo (start-scheduler)) That blocks the compilation and the generation of the .war. To circumvent this, I thought about moving the call to a startup function, but how would I call it when the server launches? If I put the call inside the handler, I'd end up with the same problem as before. Thanks! In your project.clj when declaring your Ring handler you can also specify an init (and destroy) function that is run when

Passing state as parameter to a ring handler?

回眸只為那壹抹淺笑 提交于 2019-11-30 11:54:26
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 start injecting it, or parts of it, as function parameters to the different components of the application.