funcool / catacumba Goto Github PK
View Code? Open in Web Editor NEWAsynchronous web toolkit for clojure built on top of Ratpack / Netty
Home Page: https://funcool.github.io/catacumba/latest/
License: BSD 2-Clause "Simplified" License
Asynchronous web toolkit for clojure built on top of Ratpack / Netty
Home Page: https://funcool.github.io/catacumba/latest/
License: BSD 2-Clause "Simplified" License
More details: http://www.lispcast.com/clojure-web-security
Don't know how to generate the docs, so two small corrections here:
https://funcool.github.io/catacumba/latest/#handlers-2
(def myhandler
should be defn, not def
https://funcool.github.io/catacumba/latest/#body-parsing
(println "Received data:" data)
should be body, not data
Hello! How to implement signed-cookie based session store? For setup cookies we need access to context or use returned value from write-session as new session key (like ring session stores).
I try starting the system in compchat.core
from the REPL like so:
(def system (application-system))
(alter-var-root #'system component/start)
[nREPL-worker-0] INFO ratpack.server.RatpackServer - Starting server...
[nREPL-worker-0] INFO ratpack.server.RatpackServer - Building registry...
[nREPL-worker-0] INFO ratpack.server.RatpackServer - Ratpack started for http://localhost:5050
[nREPL-worker-0] INFO ratpack.server.RatpackServer - Stopping server...
[nREPL-worker-0] INFO ratpack.server.RatpackServer - Server stopped.
[nREPL-worker-0] INFO ratpack.server.RatpackServer - Starting server...
[nREPL-worker-0] INFO ratpack.server.RatpackServer - Building registry...
[nREPL-worker-0] INFO ratpack.server.RatpackServer - Ratpack started for http://localhost:5050
and it starts. When I try to access index.html page, I get this error in the console:
[ratpack-compute-4-2] WARN ratpack.error.internal.DefaultProductionErrorHandler - Default production error handler used to render server error, please add a ratpack.error.ServerErrorHandler instance to your application (method: GET, uri: /)
java.lang.ClassCastException: clojure.lang.PersistentHashMap cannot be cast to ratpack.handling.Chain
at catacumba.impl.routing$eval14735$fn__14737.invoke(routing.clj:80)
...
May someone from team release the latest version to clojars please?
Hello. Thanks for great work!
As I understand from ratpack's documentation route params (also known as path tokens) should be proxied through nested handlers. But this example doesn't work for me:
(def routes
[[:prefix "api/v1"
[:get status]
[:get "feeds" feeds]
[:prefix "chats/:id"
[:get chat-info]]]])
api/v1/chats/10 has empty route-params
but:
(def routes
[[:error error!]
[:get index]
[:prefix "api/v1"
[:get status]
[:get "feeds" feeds]
[:get "chats/:id" chat-info]]])
Works as expected and has {:id 1} in :route-params
Why? Thanks!
I noticed that there is an interceptors example in the examples/ folder, but the tests for interceptor in commented out.
Allowing obtain the current csrf token in the handler (not only by javascript).
The documentation says: "If you want to stop the server, you just need to call the .close method on the object returned by the run-server function."
There is no .close
method on server. The correct method is .stop
!
Could you please change the documentation ?
Thanks,
G.Scacco
If you create routes like this
[routes [[:assets "public" {:dir "public"}]
[:any (utils/with-db database)]
[:prefix "ui/index/:part"
[:any atlassian/check-token-from-jira-handler]
[:by-method {:get index}]]]]
in the index function route-params is always empty.. maybe because it caches the context from the utils/with-db handler? When I place the utils/with-db higher (after the prefix then everything has the :part parameter again in the route-params
map)
Hi,
Just wanted to add a snippet of uploading a file example:
(defn upload [{:keys [data]}]
(.writeTo (:file data) (java.io/FileOutputStream. (str "./downloads/" (.getFileName (:file data))))))
Enjoy!
Add builtin support https connections.
The current api is fully synchronous and in async so it should be changed to be async.
I did a little bit of research and found (.stop ratpack-server-from-run-server)
but it's not clearly defined how to do it. A little example on this in the docs or the README (ideally both) would be welcoming ๐
The proposal is do something like this:
;; Using protocols
(def myresource
(reify IResource
IResourceIndex
(-index [context]
(http/ok "foobar"))
IResourceShow
(-show [context]
(http/ok "foobar"))
IResourceCreate
(-create [context]
(http/created "foobar"))
IResourceUpdate
(-update [context]
(http/ok "foobar"))
IResourceDelete
(-delete [context]
(http/ok "foobar"))))
;; Using multimethods
(defmulti myresource
(fn [type context] type))
(defmethod myresource :index
[_ context]
(http/ok "foobar"))
(defmethod myresource :show
[_ context]
(http/ok "foobar"))
(defmethod myresource :create
[_ context]
(http/ok "foobar"))
(defmethod myresource :update
[_ context]
(http/ok "foobar"))
(defmethod myresource :delete
[_ context]
(http/ok "foobar"))
;; Using plain functions and hash-maps
(defn index
[contex]
(http/ok "foobar"))
(defn show
[contex]
(http/ok "foobar"))
(defn create
[contex]
(http/ok "foobar"))
(defn update
[contex]
(http/ok "foobar"))
(defn delete
[contex]
(http/ok "foobar"))
(def myresource
{:index index
:show show
:create create
:update update
:delete delete})
And it will be used in this way:
(require '[catacumba.handlers.restfull :as rest])
(ct/routes [[:prefix "api/v1"
(rest/resource "authors" myauthorresource)
(rest/resource "books" mybooksresource)]])
It depends on ratpack stuff that is not implement at this moment.
Tried to get the websocket example running.
Replaced [catacumba.handlers :as hs]
with [catacumba.handlers.misc :as hs]
in the namesspace websocket-echo.core
Then in the browser I get
WebSocket connection to 'ws://localhost:5050/ws' failed: Error during WebSocket handshake: Unexpected response code: 200
The parse-body handler should ignore completly get requests.
Expose some convenience macros for make test catacumba application easier!
I am very new to clojure and now was giving catacumba a try (with leiningen).
Following the instructions in the quick start area, there is an error by retrieving the dependencies after lein run:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Exception in thread "main" java.lang.IncompatibleClassChangeError: Method ratpack.server.RatpackServer.of(Lratpack/func/Action;)Lratpack/server/RatpackServer; must be InterfaceMethodref constant, compiling:(/tmp/form-init11947645225559549126.clj:1:74) at clojure.lang.Compiler.load(Compiler.java:7391) at clojure.lang.Compiler.loadFile(Compiler.java:7317) at clojure.main$load_script.invokeStatic(main.clj:275) at clojure.main$init_opt.invokeStatic(main.clj:277) at clojure.main$init_opt.invoke(main.clj:277) at clojure.main$initialize.invokeStatic(main.clj:308) at clojure.main$null_opt.invokeStatic(main.clj:342) at clojure.main$null_opt.invoke(main.clj:339) at clojure.main$main.invokeStatic(main.clj:421) at clojure.main$main.doInvoke(main.clj:384) at clojure.lang.RestFn.invoke(RestFn.java:421) at clojure.lang.Var.invoke(Var.java:383) at clojure.lang.AFn.applyToHelper(AFn.java:156) at clojure.lang.Var.applyTo(Var.java:700) at clojure.main.main(main.java:37) Caused by: java.lang.IncompatibleClassChangeError: Method ratpack.server.RatpackServer.of(Lratpack/func/Action;)Lratpack/server/RatpackServer; must be InterfaceMethodref constant at catacumba.impl.server$run_server.invokeStatic(server.clj:145) at catacumba.impl.server$run_server.invoke(server.clj:109) at cata_web.core$_main.invokeStatic(core.clj:15) at cata_web.core$_main.doInvoke(core.clj:13) at clojure.lang.RestFn.invoke(RestFn.java:397) at clojure.lang.Var.invoke(Var.java:375) at user$eval5.invokeStatic(form-init11947645225559549126.clj:1) at user$eval5.invoke(form-init11947645225559549126.clj:1) at clojure.lang.Compiler.eval(Compiler.java:6927) at clojure.lang.Compiler.eval(Compiler.java:6917) at clojure.lang.Compiler.load(Compiler.java:7379) ... 14 more
As I unterstand, it is a problem with the SLF4J-dependency?
Thankfull for every help.
Catacumba should not start in development mode by default, because it adds complexity for people running it in production. Following the principles of:
I currently use attach-route
, but reaching into the impl
namespace feels somewhat unclean.
(defmethod catacumba.impl.routing/attach-route :guice-registry
[^Chain chain [_ binding-spec]]
(.register chain
(.apply
(Guice/registry ^Action (ch/fn->action ^BindingsSpec binding-spec))
(.getRegistry chain))))
I saw now way to do it in :setup and the initial creation of the registry is done in a private fn.
The logging docs examples are wrong.
Hi I would like to server my assets from classpath I went into the documentation of ratpack and I found this: http://ratpack.io/manual/current/launching.html#base_dir
This basically means if you want to serve assets from the classpath you need to create a markerfile .ratpack
and catacumba should call http://ratpack.io/manual/current/api/ratpack/server/ServerConfig.html#findBaseDir-java.lang.String- when you don't set a basedir (Or maybe this should be an option?). Would you like a pull request with this change?
The current one tends to be verbose and ugly, and has some drawbacks (such as when you define metadata in a function, the metadata is associated with the var and not a function and this causes unexpected behavior)
I'm experimenting with Catacumba, and likely doing something wrong. This route entry:
[:assets "x" {:dir "public" :indexes ["index.html"]}]
Behaves as I would expect, when I visit /x
(provided I've a .catacumba in resources/
). This one:
[:assets "" {:dir "public" :indexes ["index.html"]}]
Only serves the index page at /
, with a 404 for any static child resources (CSS, JS, in this case). How would I go about serving static content at the root of the resource tree? Please excuse me if I've missed something obvious.
With assets forms and similar things.
The docu says: :query-params and :header should be keywordized. But the keys are just strings.
http://funcool.github.io/catacumba/latest/#context
:query-params
{"user_id" "admin",
"cp" "/jira",
"xdm_e" "xx",
"loc" "en-US",
"user_key" "admin",
"lic" "none",
"cv" "1.1.42",
"tz" "Europe/Amsterdam",
"xdm_c" "channel-condition"}
Running version: Catacumba 0.5.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.