0

I am using a home grown small CGI Router for a simple webapp, code can be found here on github

The webapp has a login form like this

my $form = start_form( -method => 'post', -action => '/login' ); $form .= p( label('Mail'), textfield( -name => 'mail' ) ); $form .= p( label('Mail'), password_field( -name => 'pass' ) ); $form .= p( submit( -value => 'Log ind', -class => 'button button-primary' ) ); $form .= end_form(); 

and I have a router handling the post request like this

$router->add_route( 'POST', '/login', sub { if ( param ) { # Get mail and pass my $mail = $cgi->param( 'mail' ); my $pass = $cgi->param( 'password' ); # Check against user table # Set cookie and redirect to admin } # Otherwise redirect to /login print redirect( -url => '/login' ); }); 

on my local environment, osx 10.10.3, perl 5, version 18, subversion 2 (v5.18.2), this is working like expected, I submit the form and handle the login, no problem.

my production environment is a Microsoft-IIS/5.0 according to ENV{'SERVER_SOFTWARE'}

On the production environment is returning a 404 and unfortunately I am unable to get my hands on any log file that could reveal something useful.

.htaccess file on both production and local environment

# RewriteBase / DirectoryIndex index.pl index.phtml index.html RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.pl [L,QSA] 

2 Answers 2

1

The problem is most likely down to differing environments, check not just the server software but also the versions of perl and versions of the CGI.pm module. Also worth noting is that IIS can cause problems with CGI.pm due to the whole NPH thing - check the POD for CGI.pm for more details.

With regards to CGIRouter:

Out of the box CGI qw/:standard/ offers many of the features you would expect from a web framework, it has methods for creating HTML markup like anchors, paragraphs and H tags. CGI may not be as sexy as some of the modern frameworks.

It's not that CGI.pm isn't "sexy", it's simply not fit for purpose in any modern web app. Not to mention that the HTML markup functions are considered deprecated and shouldn't be used

adding a framework, any framework, would mean adding modules and dependencies which would then have to be kept up to date, as well as spending time on understanding the framework in question, it's cons and pros in order to pick the best one suited for the task at hand.

This is also a none-argument. CGI.pm has been removed from the perl core as of 5.22 so you will need to install it and its dependencies pretty soon. If you want to write a trivial RESTful web service using a simple to use framework with minimal dependencies then look at Mojolicious::Lite. For more examples and other alternatives see CGI::Alternatives.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I wrote the CGI::Router mostly for fun, it will never serve for anything critical, but thanks for the feedback
0

After doing a ton of testing, I realised, the problem is not in the router or the fact that POST is not handled by IIS. The problem is the redirect subroutine.

Whereas redirect( -url => '/admin' ); works on OSX, it's not working on IIS. On IIS the full URL has to be passed like so redirect( -url => 'http://example.com/admin' ).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.