Advertisement
swaggboi

regex-example

Jan 22nd, 2021
1,766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.06 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use Mojolicious::Lite;
  4.  
  5. get '/' => sub {
  6.     my ($c)        = @_;
  7.     my $hostHeader = $c->req->headers->host();
  8.  
  9.     if ($hostHeader =~ /www.wethepeople.win(|:[0-9]{1,5})/) {
  10.         $c->render()
  11.     }
  12.     else {
  13.         $c->redirect_to('http://www.wethepeople.win')
  14.     }
  15. } => 'index';
  16.  
  17. app->start();
  18.  
  19. # Testing with curl:
  20.  
  21. # daniel@graymember:~/misc/mojo$ curl -I http://localhost:3000 -H 'Host: www.wethepeople.win'
  22. # HTTP/1.1 200 OK
  23. # Content-Length: 2709
  24. # Date: Sat, 23 Jan 2021 00:47:54 GMT
  25. # Server: Mojolicious (Perl)
  26. # Content-Type: text/html;charset=UTF-8
  27. #
  28. # daniel@graymember:~/misc/mojo$ curl -I http://localhost:3000 -H 'Host: www.wethepeople.win:3000'
  29. # HTTP/1.1 200 OK
  30. # Date: Sat, 23 Jan 2021 00:47:58 GMT
  31. # Content-Length: 2709
  32. # Content-Type: text/html;charset=UTF-8
  33. # Server: Mojolicious (Perl)
  34. #
  35. # daniel@graymember:~/misc/mojo$ curl -I http://localhost:3000
  36. # HTTP/1.1 302 Found
  37. # Content-Length: 0
  38. # Date: Sat, 23 Jan 2021 00:48:05 GMT
  39. # Location: http://www.wethepeople.win
  40. # Server: Mojolicious (Perl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement