Giter Site home page Giter Site logo

module.web's People

Contributors

benalbrecht avatar ikitommi avatar jaydeesimon avatar lambdadbmal avatar prepor avatar weavejester avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

module.web's Issues

Removing a middleware

Instead of the default ring stacktrace middleware in the development environment I wanted to user this one https://github.com/magnars/prone but I cannot find a way to "replace" the :duct.web.middleware/stacktrace key in the :middlewares of the root handler. Is there any clean way that we can do this?

Thanks

Uncaught exception when a request body is not valid e.g. JSON

Hi,

I found that a usage of muuntaja.middleware/wrap-format is used in duct.middleware.web/format component without wrapping it into muuntaja.middleware/wrap-exception thus when a request body contains invalid JSON an exception is raised and couldn't be caught.

Quick and dirty fix could be like this:

(defmethod ig/init-key ::format [_ options]
  (fn [a]
    (mm/wrap-exception
      (mm/wrap-format a (deep-merge mc/default-options options))
      (fn [ex fmt request]
         {:status 400
          :headers {"Content-Type" "text/plain"}
          :body (str "Malformed " format " request.")}))))

But I think the best would be to allow a developer to define its own handler via options.
What do you think?

Thanks for feedback.

No implementation of method: :write-body-to-stream for internal server error

Hi,

when an exception is raised (in a Ring handler) it's caught by wrap-hide-errors middleware. Unfortunately request in wrap-hide-errors has no :muuntaja/response nor :muuntaja/request attributes and a static response :duct.handler.static/internal-server-error is not marshalled to a string, thus Ring raises an exception No implementation of method: :write-body-to-stream of protocol: #'ring.core.protocols/StreamableResponseBody found for class: clojure.lang.PersistentArrayMap.

I've tried on 0.6.4 version (because of my existing services and it's still default in lein template).

I have got a couple of solutions on my mind:

  1. Make a static response marshalled: {:status 500, :body "{\"error\":\"internal-server-error\"}"}
  2. Encode a response by a hand like this:
(try
  (handler request)
  (catch Throwable _
    (let [muuntaja-config (mc/create)
           req (mc/format-request muuntaja-config request)]
      (mc/format-response muuntaja-config req (internal-error (error-handler req))))))

What do you think?

invalid anti-forgery token

Hi,

I guess this issue might be related with issue #10

As it has just got closed, I'd rather open this new one instead of going on with that other one.

As issue reported there got fixed thanks to suggestions supplied, issue reported here arose: as I try to access a couple POST endpoints by means of Postman, I get the following error reported:

<h1>invalid anti-forgery token</h1>

Immediately before implementing fix suggested in previous issue, I had been able to access both endpoints successfully.

Solutions found so far seem too fragmentary, at least for a beginner in Duct like me...

Or out-dated: I arrive to that conclusion as Component is mentioned there which, as far as I know, has been replaced by Immutant in Duct's current version.

Full current version of edn config shown below; what's wrong with it? How should I fix it?

{:duct.core/project-ns  conduit
 :duct.core/environment :production

 :duct.middleware.buddy/authentication
 {:backend :jws
  :secret  #duct/env "JWT_SECRET"}

 :duct.module/logging {}
; :duct.module.web/api {}
 :duct.module/sql     {}
 :duct.module.web/site {}
; :duct.module/cljs     {:main conduit.core}
 
; :duct.core/handler
; {:middleware [#ig/ref :duct.middleware.web/route-aliases]}

; :duct.middleware.web/route-aliases
; {"/" "/index.html"}

 :duct.migrator/ragtime
 {:migrations [#ig/ref :conduit.migration/create-table-user
               #ig/ref :conduit.migration/create-table-follow
               #ig/ref :conduit.migration/create-table-article
               #ig/ref :conduit.migration/create-table-tag
               #ig/ref :conduit.migration/create-table-favorite
               #ig/ref :conduit.migration/create-table-comment]}

 [:duct.migrator.ragtime/sql :conduit.migration/create-table-user]
 {:up   [#duct/resource "migrations/create-table-user-2018-04-23.sql"]
  :down [#duct/resource "migrations/drop-table-user-2018-04-23.sql"]}

 [:duct.migrator.ragtime/sql :conduit.migration/create-table-follow]
 {:up   [#duct/resource "migrations/create-table-follow-2018-04-23.sql"]
  :down [#duct/resource "migrations/drop-table-follow-2018-04-23.sql"]}

 [:duct.migrator.ragtime/sql :conduit.migration/create-table-article]
 {:up   [#duct/resource "migrations/create-table-article-2018-04-23.sql"]
  :down [#duct/resource "migrations/drop-table-article-2018-04-23.sql"]}

 [:duct.migrator.ragtime/sql :conduit.migration/create-table-tag]
 {:up   [#duct/resource "migrations/create-table-tag-2018-04-23.sql"]
  :down [#duct/resource "migrations/drop-table-tag-2018-04-23.sql"]}

 [:duct.migrator.ragtime/sql :conduit.migration/create-table-favorite]
 {:up   [#duct/resource "migrations/create-table-favorite-2018-04-23.sql"]
  :down [#duct/resource "migrations/drop-table-favorite-2018-04-23.sql"]}

 [:duct.migrator.ragtime/sql :conduit.migration/create-table-comment]
 {:up   [#duct/resource "migrations/create-table-comment-2018-04-23.sql"]
  :down [#duct/resource "migrations/drop-table-comment-2018-04-23.sql"]}

 :conduit.handler.walkable/compile-schema
 {:columns [:user/email :user/token :user/username :user/bio :user/image
            :article/slug :article/title :article/description :article/body
            :article/created-at :article/updated-at
            :tag/tag
            :comment/id :comment/created-at :comment/updated-at :comment/body]

  :idents {:user/by-id       :user/id
           :user/by-username :user/username
           :users/all        "user"
           :articles/all     "article"
           :articles/feed    "article"
           :article/by-slug  :article/slug
           :article/by-id    :article/id}

  :joins {[:user/followed-by :user/followed-by-me?]
          [:user/id :follow/followee-id :follow/follower-id :user/id]

          :article/tags [:article/id :tag/article-id]

          :article/comments [:article/id :comment/article-id]

          [:article/liked-by :article/liked-by-count :article/liked-by-me?]
          [:article/id :favorite/article-id :favorite/user-id :user/id]

          :article/author [:article/author-id :user/id]

          :comment/author [:comment/author-id :user/id]}
  :reversed-joins {:user/follows :user/followed-by
                   :user/like    :article/liked-by}
  :pseudo-columns {:agg/count [:count-*]}
  :cardinality    {:user/by-id             :one
                   :user/by-username       :one
                   :article/by-id          :one
                   :article/by-slug        :one
                   :article/author         :one
                   :article/liked-by-me?   :one
                   :user/followed-by-me?   :one
                   :article/liked-by-count :one}}

 :conduit.handler.sql/run-query {}

 :conduit.handler.walkable/resolver
 #:walkable.sql-query-builder {:duct/logger #ig/ref :duct/logger
                               :run-query   #ig/ref :conduit.handler.sql/run-query
                               :sql-db      #ig/ref :duct.database.sql/hikaricp
                               :sql-schema  #ig/ref :conduit.handler.walkable/compile-schema}

 :duct.module/ataraxy
 {
;  [:get "/"]
;  ["/index.html"]
;  [:index/index-page]

  [:post "/api/users" {{:keys [user]} :body-params}]
  [:user/create user]

  [:post "/api/users/login" {{:keys [user]} :body-params}]
  [:user/login user]

  [:get "/api/profiles/" username]
  ^:jws-auth [:user/by-username username]

  [:post "/api/profiles/" username "/follow"]
  ^:jws-auth [:user/follow username]

  [:delete "/api/profiles/" username "/follow"]
  ^:jws-auth [:user/unfollow username]

  [:get "/api/articles/" slug]
  ^:jws-auth [:article/by-slug slug]

  [:get "/api/articles/" slug "/comments"]
  ^:jws-auth [:article/comments-by-slug slug]

  [:delete "/api/articles/" slug]
  ^:jws-auth [:article/destroy slug]

  [:post "/api/articles/" slug "/favorite"]
  ^:jws-auth [:article/like slug]

  [:delete "/api/articles/" slug "/favorite"]
  ^:jws-auth [:article/unlike slug]

  [:post "/api/articles/" slug "/comments" {{comment-item :comment} :body-params}]
  ^:jws-auth [:article/create-comment slug comment-item]

  [:delete "/api/articles/" slug "/comments/" id]
  ^:jws-auth [:article/destroy-comment ^int id]

  [:post "/api/articles" {{:keys [article]} :body-params}]
  ^:jws-auth [:article/create article]

  [:get "/api/articles" {params :query-params}]
  ^:jws-auth [:article/all-articles params]

  [:get "/api/articles/feed" {params :query-params}]
  ^:jws-auth [:article/feed params]

  [:get "/api/user"]
  ^:jws-auth [:user/whoami]}

 :duct.router/ataraxy {:middleware {:jws-auth #ig/ref :duct.middleware.buddy/authentication}}

 :duct.core/handler
 {:middleware [#ig/ref :duct.middleware.web/format
               #ig/ref :duct.middleware.web/defaults
               #ig/ref :duct.middleware.web/route-aliases]}

 :duct.middleware.web/defaults
 {:static {:resources ["public"]}}

 :duct.middleware.web/format {}
 :duct.middleware.web/route-aliases
 {"/" "/index.html"}
 
 :conduit.handler.user/whoami
 {:db         #ig/ref :duct.database/sql
  :jwt-secret #duct/env "JWT_SECRET"}

 :conduit.handler.user/by-username
 {:resolver #ig/ref :conduit.handler.walkable/resolver}

 :conduit.handler.article/destroy
 {:db #ig/ref :duct.database/sql}

 :conduit.handler.article/by-slug
 {:resolver #ig/ref :conduit.handler.walkable/resolver}

 :conduit.handler.article/comments-by-slug
 {:resolver #ig/ref :conduit.handler.walkable/resolver}

 :conduit.handler.user/create
 {:db         #ig/ref :duct.database/sql
  :jwt-secret #duct/env "JWT_SECRET"}

 :conduit.handler.article/all-articles
 {:resolver #ig/ref :conduit.handler.walkable/resolver}

 :conduit.handler.article/feed
 {:resolver #ig/ref :conduit.handler.walkable/resolver}

 :conduit.handler.article/create
 {:db #ig/ref :duct.database/sql}

 :conduit.handler.article/like
 {:db #ig/ref :duct.database/sql}

 :conduit.handler.article/unlike
 {:db #ig/ref :duct.database/sql}

 :conduit.handler.user/follow
 {:db #ig/ref :duct.database/sql}

 :conduit.handler.user/unfollow
 {:db #ig/ref :duct.database/sql}

 :conduit.handler.article/create-comment
 {:db #ig/ref :duct.database/sql}

 :conduit.handler.article/destroy-comment
 {:db #ig/ref :duct.database/sql}

 :conduit.handler.user/login
 {:db         #ig/ref :duct.database/sql
  :jwt-secret #duct/env "JWT_SECRET"}

; :conduit.handler.index/index-page {}
 
}

Thanks in advance !

Luis

The middleware aren't updated to support async handlers with ring

None of the middleware in this module supports async handlers.

I haven't yet figured out how to implement these to support async handlers but thought I could at least add an issue regarding it.

If no one have the time to fix I can probably supply an PR next week or so.

Support log-requests' log level configurable

Hi,

I made a PR to support log-requests' log level configurable.

#20

I would like to displace log-requests message from my application, but I could not find any solution.
So I made a little code change to change the log level.

Thank you.

Make compojure dependency excludable?

I'm using ataraxy instead of compojure for routing, so I want to :exclusions [compojure] dependency. But it got error due to :duct.router/cascading router depend on it.

I think we should make :duct.router/cascading independent on compojure (by copy compojure/routes fn into cascading router?)

:middleware doesn't effect static files.

Middleware added to the :duct.core/handler :middleware vector doesn't seem to have any effect on static files. This is unfortunate, as gzip (added via the ring-gzip middleware) is hugely important for compiled cljs.

Middleware correctly effects routes using :duct.router/cascading. However, "resource" compojure routes added using :duct.router/cascading don't seem to do anything, so that's little help.

The best solution I've been able to find is to explicitely declare a :duct.server.http with a handler that wraps the :duct.core/handler in whatever middleware I desire. This, I feel, is kludgy and inelegant compared to declaring a :handler :middleware.

Explain how it works

Could you explain how this module works. Could you describe at a high level how it manipulated the config data.
In particular, I am interested to understand how the handler data is passed to the :duct.server.http key.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.