[ClojureScript] Re: "Redirect-after-post" using secretary?

2015-09-12 Thread Thomas Heller
Sorry I got that totally wrong. The XHR actually follows redirects, it just 
doesn't do it like the browser usually does and does not change its location.

The response you are seeing is the final result of the redirect, eg the content 
of /person. You cannot cancel the redirect either as far as I'm aware.

You'll probably need to change the server side response.


On Saturday, September 12, 2015 at 8:53:59 PM UTC+2, Hari Krishnan wrote:
> On Saturday, September 12, 2015 at 2:11:31 AM UTC-7, Thomas Heller wrote:
> > You are using an ajax request which does not follow the same rules as a 
> > normal browser navigation requests. It will not follow redirects for 
> > example.
> > 
> > I don't know what ajax lib you are using but the general solution will be:
> > 
> > fire request
> > wait for response
> > check response code of request
> > if redirect get location header
> > do cleanup of your local app
> > then set document.location.href to location url
> > the page will unload and load /login as "normal"
> > 
> > or you could rewrite the server to not send a redirect but send the 
> > location encoded as data.
> > 
> > HTH,
> > /thomas
> > 
> > 
> > 
> > > 
> > > The response to curl is as follows:
> > > 
> > > HTTP/1.1 302 Found
> > > Server: undertow
> > > X-XSS-Protection: 1; mode=block
> > > Location: http://localhost:3000/login  <-
> > > X-Frame-Options: SAMEORIGIN
> > > Date: Fri, 11 Sep 2015 21:06:28 GMT
> > > Connection: keep-alive
> > > X-Content-Type-Options: nosniff
> > > Content-Type: text/html; charset=utf-8  <
> > > Content-Length: 0
> > > 
> > > However, the reagent form is not getting redirected to he /login form.  
> > > It remains in the same form.  On the console, I can see, however, the 
> > > login page is streamed as an HTML. ( I am using "/login" as just as an 
> > > example.).
> > > 
> > > The original reagent page is doing a request with CLJS-AJAX POST.
> > > 
> > > Any hint is much appreciated.  Thanks,
> > > 
> > > Regards,
> > > Hari
> 
> Hi Thomas,
> 
> Thanks for the answer.  I still have one more issue related to this logic.  
> When I set the :location at the header onn the server side, what I see on the 
> client console (Chrome) is as follows (logging the response from the server): 
>  I don't see the location key/value, instead, I see the whole page in HTML.  
> Any hint?  tried with different doc-types.
> 
> {:status 200, 
>   :success true, 
>   :body "\r\n\r\n\r\n\r\n  \r\n  \r\n  
> --\r\n", 
> 
> :headers {"date" "Sat, 12 Sep 2015 18:27:30 GMT", "x-content-type-options" 
> "nosniff", "server" "undertow", "x-frame-options" "SAMEORIGIN", 
> "content-type" "text/html; charset=utf-8", "connection" "keep-alive", 
> "content-length" "3928", "x-xss-protection" "1; mode=block"}, 
> :trace-redirects ["/person" "/person"], 
> :error-code :no-error, 
> :error-text ""}
> 
> ON THE Client side, I solved the redirect issue with the following code:
> 
> (.assign js/location "/job")
> 
> But I couln't find the location in the header.  So I hard-coded it here!
> 
> Thanks for the response.
> 
> Regards,
> Hari

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Re: "Redirect-after-post" using secretary?

2015-09-12 Thread Hari Krishnan
On Saturday, September 12, 2015 at 2:11:31 AM UTC-7, Thomas Heller wrote:
> You are using an ajax request which does not follow the same rules as a 
> normal browser navigation requests. It will not follow redirects for example.
> 
> I don't know what ajax lib you are using but the general solution will be:
> 
> fire request
> wait for response
> check response code of request
> if redirect get location header
> do cleanup of your local app
> then set document.location.href to location url
> the page will unload and load /login as "normal"
> 
> or you could rewrite the server to not send a redirect but send the location 
> encoded as data.
> 
> HTH,
> /thomas
> 
> 
> 
> > 
> > The response to curl is as follows:
> > 
> > HTTP/1.1 302 Found
> > Server: undertow
> > X-XSS-Protection: 1; mode=block
> > Location: http://localhost:3000/login  <-
> > X-Frame-Options: SAMEORIGIN
> > Date: Fri, 11 Sep 2015 21:06:28 GMT
> > Connection: keep-alive
> > X-Content-Type-Options: nosniff
> > Content-Type: text/html; charset=utf-8  <
> > Content-Length: 0
> > 
> > However, the reagent form is not getting redirected to he /login form.  It 
> > remains in the same form.  On the console, I can see, however, the login 
> > page is streamed as an HTML. ( I am using "/login" as just as an example.).
> > 
> > The original reagent page is doing a request with CLJS-AJAX POST.
> > 
> > Any hint is much appreciated.  Thanks,
> > 
> > Regards,
> > Hari

Hi Thomas,

Thanks for the answer.  I still have one more issue related to this logic.  
When I set the :location at the header onn the server side, what I see on the 
client console (Chrome) is as follows (logging the response from the server):  
I don't see the location key/value, instead, I see the whole page in HTML.  Any 
hint?  tried with different doc-types.

{:status 200, 
:success true, 
:body "\r\n\r\n\r\n\r\n  \r\n  \r\n  
--\r\n", 

:headers {"date" "Sat, 12 Sep 2015 18:27:30 GMT", "x-content-type-options" 
"nosniff", "server" "undertow", "x-frame-options" "SAMEORIGIN", "content-type" 
"text/html; charset=utf-8", "connection" "keep-alive", "content-length" "3928", 
"x-xss-protection" "1; mode=block"}, 
:trace-redirects ["/person" "/person"], 
:error-code :no-error, 
:error-text ""}

ON THE Client side, I solved the redirect issue with the following code:

(.assign js/location "/job")

But I couln't find the location in the header.  So I hard-coded it here!

Thanks for the response.

Regards,
Hari

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


Re: [ClojureScript] Easiest way to compile cljs live

2015-09-12 Thread Mike Fikes
Yes, planck -v is overly verbose right now (owing to it showing the ancillary 
JavaScript used to emit vars for def forms).

I’d recommend :repl-verbose true for any ClojureScript REPL instead. For 
example, modify the last line of script/noderepljs that ships with the compiler 
to be

  (repl/repl (node/repl-env $1) :repl-verbose true)”

- Mike

> On Sep 12, 2015, at 2:36 PM, Yehonathan Sharvit  wrote:
> 
> On Friday, 11 September 2015 08:24:01 UTC+3, Linus Ericsson  wrote:
>> Figwheel is nice, even though I just get the repl in the command-line there 
>> (no autocomplete etc).
>> 
>> The features for compiling and update client side cljs is really really good.
>> 
>> https://github.com/bhauman/lein-figwheel
>> 
>> Den 11 sep 2015 04:22 skrev "Mike Fikes" :
>> 
>> 1. Are you setting :repl-options in project.clj? If so, I suspect that only 
>> affects Lein’s Clojure REPL.  See 
>> https://github.com/clojure/clojurescript/wiki/Running-REPLs and, in 
>> particular, :repl-verbose true would be provided in the map argument to 
>> cljs.repl/repl*.
>> 
>> 
>> 2. If you are running Planck on OS X, the `-v` option puts Planck into 
>> verbose mode, showing compiled JavaScript. If on OS X but running a REPL 
>> that ships with ClojureScript (like script/noderepljs) or a REPL that is 
>> based on from ClojureScript’s cljs.repl, comment #1 above applies.
>> 
>> 
>> 
>> 
>> On Sep 10, 2015, at 9:41 AM, Yehonathan Sharvit  wrote:
>> 
>> 1. I set   :repl-options {:repl-verbose true} but the repl didn't show any js
>> 2. I'm on mac but I can't see the compiled js on the repl
>> 
>> 
>> 
>> 
>> 
>> -- 
>> 
>> Note that posts from new members are moderated - please be patient with your 
>> first post.
>> 
>> --- 
>> 
>> You received this message because you are subscribed to the Google Groups 
>> "ClojureScript" group.
>> 
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojurescrip...@googlegroups.com.
>> 
>> To post to this group, send email to clojur...@googlegroups.com.
>> 
>> Visit this group at http://groups.google.com/group/clojurescript.
> 
> Thanks Mike.
> 
> I am able to see compiled js in planck (I was using an old version before)
> 
> But the repl approach is not so easy when you have a couple of lines of code.
> 
> Try to see the js of this piece of cljs code:
> 
> (deftype x [val])
> 
> (defprotocol Wow
>  (aa [this]))
> 
> (extend-type x
>  Wow
>  (aa [this] "aa from extend-type"))
> 
> 
> (extend-protocol Wow
>  x
>  (aa [this] "aa from extend-protocol"))
> 
> (aa (x. "a"))
> 
> 
> Is there another tool availble out there? Maybe  a web page that compiles 
> cljs?
> 
> 
> 
> -- 
> Note that posts from new members are moderated - please be patient with your 
> first post.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojurescript+unsubscr...@googlegroups.com.
> To post to this group, send email to clojurescript@googlegroups.com.
> Visit this group at http://groups.google.com/group/clojurescript.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Re: Redirect in a SPA on the server side.

2015-09-12 Thread Val Waeselynck
Le samedi 12 septembre 2015 20:56:30 UTC+2, Hari Krishnan a écrit :
> On Saturday, September 12, 2015 at 6:19:41 AM UTC-7, Val Waeselynck wrote:
> > Because you're working with AJAX, you do not want your server to redirect. 
> > You want to just send the data to the server, and then change the URL of 
> > the page with something like 
> > 
> > window.location.href = 
> > 
> > Le samedi 12 septembre 2015 05:34:58 UTC+2, Hari Krishnan a écrit :
> > > Hello All,
> > > 
> > > 
> > > I am working on a use case as follows:  The UI is with reagent, re-frame 
> > > for subscription & Luminus, and for the backend, I use Compojure.  I also 
> > > tried with Liberator, but for simplicity, I am using only Compojure now.
> > > 
> > > I also use Secretary & cljs-ajax for SPA routing and ajax.
> > > 
> > > -> User brings up "/person"  URL, and use a set of actions.  The page 
> > > data is sent to the backend, gets validated and saved to the DB.  Then 
> > > the user has to be re-directed to "/job".  If there is any error, the 
> > > errors will be displayed on the "/person"  page.
> > > 
> > > There are two application components -- one with the URL "/person",and 
> > > the other with "/job".  With each of these, I have a few related pages, 
> > > and I am creating them as SPA with Reagent.
> > > 
> > > The question is how do I redirect to the "/job"?
> > > 
> > > Client Side Code (only the the relevant ones)
> > > 
> > > (POST "/person"
> > >   {:headers {"Accept" "application/clojure"}
> > >:params @doc
> > > 
> > >:handler ex-handler
> > >:error-handler ex-error-handler})
> > > 
> > > Server:
> > > (defn process-person []
> > >   (-> (redirect "/job" :permanent)
> > >   (header "Content-Type"  "text/html; charset=utf-8")
> > >   (header "Location"  "/job")
> > >   )
> > >   )
> > > 
> > > (POST "/person" [params] (process-person params))
> > > 
> > > Interestingly, on the console, I can see the HTML for the "job" page.  Do 
> > > I have to change the Secretary code to make it happen?
> > > 
> > > Any help is much appreciated.
> > > 
> > > Regards,
> > > Hari
> 
> Hi Val,
> 
> Thanks for the answer.  I still have one more issue related to this logic.  
> When I set the :location at the header onn the server side, what I see on the 
> client console (Chrome) is as follows (logging the response from the server): 
>  I don't see the location key/value, instead, I see the whole page in HTML.  
> Any hint?  tried with different doc-types.
> 
> {:status 200, 
>   :success true, 
>   :body "\r\n\r\n\r\n\r\n  \r\n  \r\n  
> --\r\n", 
> 
> :headers {"date" "Sat, 12 Sep 2015 18:27:30 GMT", "x-content-type-options" 
> "nosniff", "server" "undertow", "x-frame-options" "SAMEORIGIN", 
> "content-type" "text/html; charset=utf-8", "connection" "keep-alive", 
> "content-length" "3928", "x-xss-protection" "1; mode=block"}, 
> :trace-redirects ["/person" "/person"], 
> :error-code :no-error, 
> :error-text ""}
> 
> (defresource post-person-resource
>  :available-media-types [ "application/clojure"]
>  :allowed-methods [:post]
>  :post! (fn [context] ())
>  :post-redirect? (fn [ctx] {:location "/job"})
> 
> ON THE Client side, I solved the redirect issue with the following code:
> 
> (.assign js/location "/job")
> 
> But I couln't find the location in the header.  So I hard-coded it here!
> 
> Thanks for the response.
> 
> Regards,
> Hari

This is how HTTP works. What you're seeing is the "target" response of the 
redirection, not the "redirect" response (which has a 301 status code and a 
"Location" header).

Again, this weird hybridation of classical web pages / AJAX behavior is 
probably the root of all evil here :). IMO the way to go here is to not 
redirect from the server, this is a decision to be made by the client (and your 
client knowing why it fetched the data, it probably also knows where to go next 
:) ).

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Puzzling error: Namespace "com.cognitect.transit.util" already declared.

2015-09-12 Thread J . Pablo Fernández
Hello,

I'm working on loading and running my ClojureScript application on Nashorn, a 
JavaScript implementation that runs inside Java. The purpose is to pre-render 
single page applications. I managed to do it with avery simple application and, 
in case anybody is curious, I'm publishing the results here: 
https://carouselapps.com/2015/09/11/isomorphic-clojurescriptjavascript-for-pre-rendering-single-page-applications-part-1/

When trying to run bigger applications I'm running into lots of little errors 
and issues and solving them one by one. There's one error though that is really 
puzzling. When I require ajax.core, as in:

(ns projectx.handlers
  (:require [ajax.core :as ajax]))

I get this error:

Error: Namespace "com.cognitect.transit.util" already declared.

The traceback is:

Caused by: :19664:6 Error: Namespace "com.cognitect.transit.util" already 
declared.
at 
jdk.nashorn.internal.objects.NativeError.initException(NativeError.java:137)
at jdk.nashorn.internal.objects.NativeError.(NativeError.java:102)
at jdk.nashorn.internal.objects.NativeError.(NativeError.java:106)
at jdk.nashorn.internal.objects.NativeError.(NativeError.java:110)
at 
jdk.nashorn.internal.objects.NativeError.constructor(NativeError.java:129)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$1544$602593A$\^eval\_.provide(:19664)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$1681$\^eval\_.:program$:split-9(:57262)
at jdk.nashorn.internal.scripts.Script$1285$\^eval\_.:program()
at 
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
at 
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
at 
jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
at 
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:437)
... 66 more


line 57262 indeed contains: 

goog.provide("com.cognitect.transit.util");

Trying to figure out how it could be duplicated:

$ grep -R provide.*com\.cognitect\.transit\.util .
./resources/public/js/app/com/cognitect/transit/util.js:goog.provide("com.cognitect.transit.util");
./resources/public/js/server-side/com/cognitect/transit/util.js:goog.provide("com.cognitect.transit.util");
./resources/public/js/server-side.js:goog.provide("com.cognitect.transit.util");

sever-side.js is the only file that is being loaded in Nashorn. Nothing from 
app should ever be loaded as it is a different build target and I don't 
understand how util.js could be loaded, but just in case I commented it out and 
I keep receiving the same error. Which only happens when I'm loading ajax.core.

Any ideas what's going on here? This one left me scratching my head as no 
matter how I poke it, nothing makes sense.

Thanks.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


Re: [ClojureScript] Favorite Web Stacks and why

2015-09-12 Thread Jamie Orchard-Hays
Thanks, y’all. I’m particularly interested in the server-side stacks 
programmers are using these days.

Jamie


> On Sep 11, 2015, at 12:45 PM, Colin Yates  wrote:
> 
> https://github.com/stuartsierra/component
> 
> On 11 September 2015 at 17:42, Marc Fawzi  wrote:
>> What is Stuart's Component system? :)
>> 
>> Sent from my iPhone
>> 
>>> On Sep 11, 2015, at 9:40 AM, Colin Yates  wrote:
>>> 
>>> - sente, transmit, edn and core.async for a seamless two-way 'channel'
>>> between front and backend
>>> - re-frame for subscriptions and just-enough architecture for your UI
>>> - reagent for a very light-touch way of describing your UI (om could
>>> also be placed here)
>>> - http-kit on the server side
>>> - prismatic schema everywhere
>>> - Stuart's Component system for just enough plumbing to manage components
>>> - Cursive for the best Clojure IDE in the world or emacs/cider for the
>>> best text editor in the world :-)
>>> 
>>> (Cursive and Cider - you both rock!)
>>> 
>>> HTH
>>> 
 On 11 September 2015 at 15:21, Jamie Orchard-Hays  
 wrote:
 I’m curious what your favorite web stacks in Clojure and Clojurescript are 
 these days. Client and server libs you like to use and what you like and 
 don’t like about them.
 
 Cheers,
 
 Jamie
 
 --
 Note that posts from new members are moderated - please be patient with 
 your first post.
 ---
 You received this message because you are subscribed to the Google Groups 
 "ClojureScript" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojurescript+unsubscr...@googlegroups.com.
 To post to this group, send email to clojurescript@googlegroups.com.
 Visit this group at http://groups.google.com/group/clojurescript.
>>> 
>>> --
>>> Note that posts from new members are moderated - please be patient with 
>>> your first post.
>>> ---
>>> You received this message because you are subscribed to the Google Groups 
>>> "ClojureScript" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to clojurescript+unsubscr...@googlegroups.com.
>>> To post to this group, send email to clojurescript@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/clojurescript.
>> 
>> --
>> Note that posts from new members are moderated - please be patient with your 
>> first post.
>> ---
>> You received this message because you are subscribed to the Google Groups 
>> "ClojureScript" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojurescript+unsubscr...@googlegroups.com.
>> To post to this group, send email to clojurescript@googlegroups.com.
>> Visit this group at http://groups.google.com/group/clojurescript.
> 
> -- 
> Note that posts from new members are moderated - please be patient with your 
> first post.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojurescript+unsubscr...@googlegroups.com.
> To post to this group, send email to clojurescript@googlegroups.com.
> Visit this group at http://groups.google.com/group/clojurescript.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Re: Redirect in a SPA on the server side.

2015-09-12 Thread Hari Krishnan
On Saturday, September 12, 2015 at 12:33:18 PM UTC-7, Val Waeselynck wrote:
> Le samedi 12 septembre 2015 20:56:30 UTC+2, Hari Krishnan a écrit :
> > On Saturday, September 12, 2015 at 6:19:41 AM UTC-7, Val Waeselynck wrote:
> > > Because you're working with AJAX, you do not want your server to 
> > > redirect. You want to just send the data to the server, and then change 
> > > the URL of the page with something like 
> > > 
> > > window.location.href = 
> > > 
> > > Le samedi 12 septembre 2015 05:34:58 UTC+2, Hari Krishnan a écrit :
> > > > Hello All,
> > > > 
> > > > 
> > > > I am working on a use case as follows:  The UI is with reagent, 
> > > > re-frame for subscription & Luminus, and for the backend, I use 
> > > > Compojure.  I also tried with Liberator, but for simplicity, I am using 
> > > > only Compojure now.
> > > > 
> > > > I also use Secretary & cljs-ajax for SPA routing and ajax.
> > > > 
> > > > -> User brings up "/person"  URL, and use a set of actions.  The page 
> > > > data is sent to the backend, gets validated and saved to the DB.  Then 
> > > > the user has to be re-directed to "/job".  If there is any error, the 
> > > > errors will be displayed on the "/person"  page.
> > > > 
> > > > There are two application components -- one with the URL "/person",and 
> > > > the other with "/job".  With each of these, I have a few related pages, 
> > > > and I am creating them as SPA with Reagent.
> > > > 
> > > > The question is how do I redirect to the "/job"?
> > > > 
> > > > Client Side Code (only the the relevant ones)
> > > > 
> > > > (POST "/person"
> > > >   {:headers {"Accept" "application/clojure"}
> > > >:params @doc
> > > > 
> > > >:handler ex-handler
> > > >:error-handler ex-error-handler})
> > > > 
> > > > Server:
> > > > (defn process-person []
> > > >   (-> (redirect "/job" :permanent)
> > > >   (header "Content-Type"  "text/html; charset=utf-8")
> > > >   (header "Location"  "/job")
> > > >   )
> > > >   )
> > > > 
> > > > (POST "/person" [params] (process-person params))
> > > > 
> > > > Interestingly, on the console, I can see the HTML for the "job" page.  
> > > > Do I have to change the Secretary code to make it happen?
> > > > 
> > > > Any help is much appreciated.
> > > > 
> > > > Regards,
> > > > Hari
> > 
> > Hi Val,
> > 
> > Thanks for the answer.  I still have one more issue related to this logic.  
> > When I set the :location at the header onn the server side, what I see on 
> > the client console (Chrome) is as follows (logging the response from the 
> > server):  I don't see the location key/value, instead, I see the whole page 
> > in HTML.  Any hint?  tried with different doc-types.
> > 
> > {:status 200, 
> > :success true, 
> > :body "\r\n\r\n\r\n\r\n  \r\n  \r\n  
> > --\r\n", 
> > 
> > :headers {"date" "Sat, 12 Sep 2015 18:27:30 GMT", "x-content-type-options" 
> > "nosniff", "server" "undertow", "x-frame-options" "SAMEORIGIN", 
> > "content-type" "text/html; charset=utf-8", "connection" "keep-alive", 
> > "content-length" "3928", "x-xss-protection" "1; mode=block"}, 
> > :trace-redirects ["/person" "/person"], 
> > :error-code :no-error, 
> > :error-text ""}
> > 
> > (defresource post-person-resource
> >  :available-media-types [ "application/clojure"]
> >  :allowed-methods [:post]
> >  :post! (fn [context] ())
> >  :post-redirect? (fn [ctx] {:location "/job"})
> > 
> > ON THE Client side, I solved the redirect issue with the following code:
> > 
> > (.assign js/location "/job")
> > 
> > But I couln't find the location in the header.  So I hard-coded it here!
> > 
> > Thanks for the response.
> > 
> > Regards,
> > Hari
> 
> This is how HTTP works. What you're seeing is the "target" response of the 
> redirection, not the "redirect" response (which has a 301 status code and a 
> "Location" header).
> 
> Again, this weird hybridation of classical web pages / AJAX behavior is 
> probably the root of all evil here :). IMO the way to go here is to not 
> redirect from the server, this is a decision to be made by the client (and 
> your client knowing why it fetched the data, it probably also knows where to 
> go next :) ).

Hi Val,

Got it.  Thanks for the response.  A good guideline.  I needed that validation.

Regards,
Hari

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Re: "Redirect-after-post" using secretary?

2015-09-12 Thread Thomas Heller
You are using an ajax request which does not follow the same rules as a normal 
browser navigation requests. It will not follow redirects for example.

I don't know what ajax lib you are using but the general solution will be:

fire request
wait for response
check response code of request
if redirect get location header
do cleanup of your local app
then set document.location.href to location url
the page will unload and load /login as "normal"

or you could rewrite the server to not send a redirect but send the location 
encoded as data.

HTH,
/thomas



> 
> The response to curl is as follows:
> 
> HTTP/1.1 302 Found
> Server: undertow
> X-XSS-Protection: 1; mode=block
> Location: http://localhost:3000/login  <-
> X-Frame-Options: SAMEORIGIN
> Date: Fri, 11 Sep 2015 21:06:28 GMT
> Connection: keep-alive
> X-Content-Type-Options: nosniff
> Content-Type: text/html; charset=utf-8  <
> Content-Length: 0
> 
> However, the reagent form is not getting redirected to he /login form.  It 
> remains in the same form.  On the console, I can see, however, the login page 
> is streamed as an HTML. ( I am using "/login" as just as an example.).
> 
> The original reagent page is doing a request with CLJS-AJAX POST.
> 
> Any hint is much appreciated.  Thanks,
> 
> Regards,
> Hari

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.