duct

javi 2019-05-07T13:19:35.028300Z

HI guys, just started learning duct ( although i use integrant in the front end for a framework i am building ). I have used luminus for a backend so familiar with the main ring / compojure ecosystem. So, a possibly stupid question, but i have found no examples to orient myself ... how would i implement cors when using :duct.module.web/api or :duct.router/cascading ? any direction would be appreciated. cheers

2019-05-07T21:08:26.029200Z

@clojurians827 I think it is happening because :duct.migrator/ragtime and [:duct.migrator.ragtime/sql :todo.migration/create-entries] should be in the base profile

2019-05-07T21:09:03.029500Z

{:duct.profile/base
 {:duct.core/project-ns todo

  :duct.router/ataraxy
  {:routes   {[:get "/"] [:todo.handler/index]}
   :handlers {:todo.handler/index #ig/ref :todo.handler/index}}
 
 [:duct.handler.static/ok :todo.handler/index]
 {:body {:entries "/entries"}}
 
 :duct.migrator/ragtime
 {:migrations [#ig/ref :todo.migration/create-entries]}

 [:duct.migrator.ragtime/sql :todo.migration/create-entries]
  {:up ["CREATE TABLE entries (id INTEGER PRIMARY KEY, content TEXT)"]
   :down ["DROP TABLE entries"]}}

 :duct.profile/dev   #duct/include "dev"
 :duct.profile/local #duct/include "local"
 :duct.profile/prod  {}

 :duct.module/logging {}
 :duct.module.web/api {}
 :duct.module/sql {}}

👍 1
2019-05-07T21:09:08.029800Z

Like this

2019-05-07T21:29:43.031600Z

@fj.abanses you should learn about middleware for :duct.core/handler. Look to https://github.com/duct-framework/core#keys about :duct.core/handler. But note https://github.com/duct-framework/module.web/blob/47a07008d42a349e77131ee35fe552b9f67e3a1a/CHANGELOG.md#070-alpha3-2018-09-28

2019-05-07T21:34:50.033100Z

For example it might look like

:duct.handler/root
{:middleware [#ig/ref :your.middleware/cors]} ;; middleware will be appended by default
:your.middleware/cors {}
Also look into https://github.com/duct-framework/core/blob/04f5378f4a8d73af4f208c5f5e8125d53506fbd9/src/duct/core.clj#L81