Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

redirecting Molicious app to https

by Ea (Hermit)
on Aug 25, 2016 at 14:03 UTC ( #1170437=CUFP: print w/replies, xml ) Need Help??

(Quick post)

Searched the fine web and didn't find a quick answer to how to redirect an http request to https in Mojolicious. I wanted to insure that logins were always secure. Finally cobbled together a solution and thought I should share and maybe get some improvements.

  1. Run 2 webservers: one to handle http and the other to handle https, which for me is two incantations of hypnotoad
  2. Add a route in your http App
    $r->get('/login')->to('MyApp#https_redirect');
  3. Add a sub to the http Controller
    sub https_redirect { my $self = shift; my $secure = $self->req->url->to_abs->scheme('https')->port(443); $self->redirect_to($secure); }
  4. Profit!

All the sub does is redirect the request to the new protocol at the same url. I've seen a method in the docs to a is_secure method which could be useful somewhere. Also, I tried using $r->any('/login'), but it doesn't work for me and I'm moving on.

Yes, I probably could've gotten a better answer inside 2 minutes on IRC (people are so very helpful), but it never occurs to me until afterwards.

Sometimes I can think of 6 impossible LDAP attributes before breakfast.

http://act.yapc.eu/lpw2016/ It's that time of year again!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1170437]
Approved by stevieb
Front-paged by beech
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2018-07-19 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (413 votes). Check out past polls.

    Notices?