Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wf:redirect does not work. #61

Closed
radetsky opened this issue May 6, 2014 · 3 comments
Closed

wf:redirect does not work. #61

radetsky opened this issue May 6, 2014 · 3 comments

Comments

@radetsky
Copy link

radetsky commented May 6, 2014

Hi, it's me again. :-)

I saw in examples ( skyline ) next code:

main() ->
case wf:user() of undefined -> wf:redirect("/login"); _ -> [#dtl{file = wf:cache(mode), ext="dtl",bindings=[{title,<<"Account">>},{body,body()}]}] end.

In case of undefined It's not working. Why ? Cowboy returns empty page with next headers:

HTTP/1.1 200 OK
connection: keep-alive
server: Cowboy
date: Tue, 06 May 2014 19:07:55 GMT
content-length: 0
set-cookie: n2o-sid=1AKKkVnwL+qF4A4gSKYapA==; Version=1; Expires=Wed, 07-May-2014 19:07:55 GMT; Max-Age=86400; Path=/

But redirect works well when it called from event(X). WTF ?
Version HEAD.

@radetsky radetsky changed the title wf:redirect does not work. wf:redirect does not work. May 6, 2014
@m-2k
Copy link
Contributor

m-2k commented May 7, 2014

Redirection does not work in the function main/0, because wf:redirect uses wf:wire transmission for Actions in the browser. Thus because the page does not load; and does not load javascripts that are present In standard template and are responsible for the communication server and the client. Action #wire simply can not be executed in the browser because of lack of connection is initialized through n2o_bullet.

I suggest using the following scheme:

  • Create template empty.html
<html>
<head>
  <script>{{script}}</script>
  <script src='/static/nitrogen/bullet.js' type='text/javascript' charset='utf-8'></script>
  <script src='/static/nitrogen/n2o.js' type='text/javascript' charset='utf-8'></script>
</head>
</html>
  • And redirect as follows:
main() -> wf:redirect("/login"), #dtl{file = "empty"}.

It will be correct to redirect in the main/0 function.

Now the browser will receive HTML with links to the scripts (<script>...</script> in <head> section), download the javascripts. Loading scripts will create a connection through which will be transferred action #wire (window.location = '/login'). Thereafter immediately be redirected.

Enjoy.

@radetsky
Copy link
Author

radetsky commented May 7, 2014

Thank you. It's works now. Before n2o.js and bullet.js developer need to add jQuery.js.

@m-2k
Copy link
Contributor

m-2k commented May 7, 2014

N2O version 1.4+ does not require jQuery and uses only native javascript.

@5HT 5HT closed this as completed May 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants