Posted By

dbiesecke on 06/23/14


Tagged

perl cgi Plack


Versions (?)

Plack maps multiple pages


 / Published in: Perl
 

URL: https://stackoverflow.com/questions/19178044/using-plack-app-with-a-reverse-proxy-plackmiddlewaredebug?answertab=active#tab-top

Maps multiple apps with mount and URLMap

  1. #!/usr/bin/perl --
  2. #~ plack-debug-mounted.pl
  3. #~ 2013-10-17-02:59:26
  4. #~
  5. ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*"
  6. #!/usr/bin/perl --
  7. use CGI();
  8. use Data::Dump qw/ dd pp /;
  9. use Path::Tiny qw/ path /;
  10. use Plack::Builder;
  11. use Plack::Runner;
  12.  
  13. my $selfsourceapp = sub {
  14. '200',
  15. [ 'Content-Type' => 'text/plain', ],
  16. [ path( __FILE__ )->slurp_raw ],
  17. ];
  18. };
  19. my $dumperapp = sub {
  20. my $q = CGI->new( $_[0] );
  21. '200', [
  22. 'Content-Type' => 'text/html',
  23. 'Content-Length' => '2',
  24. ], [
  25. $q->start_html( -title => 'dumpenv.psgi' ),
  26. $q->h1( $_[0]->{SCRIPT_NAME} ),
  27. $q->Dump, $q->end_html,
  28. ],
  29. ];
  30. };
  31.  
  32. my $indexapp = sub {
  33. '200',
  34. [ 'Content-Type' => 'text/html', ],
  35. [
  36. q{<doctype html>
  37. <html lang="en-US" charset="UTF-8">
  38. <title> Plack perlology </title>
  39. <body>
  40. <p> A Plack::Middleware::Debug free zone
  41. <br> <a href="/"> this </a>
  42. <br> <a href="/dumpenv"> dupenv </a>
  43. <br> <a href="/selfsrc"> selfsrc </a>
  44. <p> Get <c>Plack::Middleware::Debug</c> <b> ed </b>
  45. <br> <a href="/debugged/"> /debugged/ this </a>
  46. <br> <a href="/debugged/dumpenv"> /debugged/dupenv </a>
  47. <br> <a href="/debugged/selfsrc"> /debugged/selfsrc </a>
  48. <p> Come get some
  49. <br> <a href="/debugged/debug_toolbar/toolbar.min.css">
  50. /debugged/debug_toolbar/toolbar.min.css
  51. </a>
  52. <br> <a href="/debugged/debug_toolbar/toolbar.min.js">
  53. /debugged/debug_toolbar/toolbar.min.js
  54. </a>
  55. <p> Cant get this
  56. <br> <a href="/debug_toolbar/toolbar.min.css">
  57. /debug_toolbar/toolbar.min.css
  58. </a>
  59. <br> <a href="/toolbar.min.css">
  60. /toolbar.min.css
  61. </a>
  62.  
  63. </body><!-- before this Plack::Middleware::Debug inserts, viewsource!! -->
  64. }
  65. ],
  66. ];
  67. };
  68.  
  69. my $finalapp = builder {
  70. mount '/debugged' => builder {
  71. enable 'Debug', panels => [
  72. qw/
  73. Timer
  74. Response
  75. Environment
  76. Session
  77. Parameters
  78. /
  79. ];
  80. mount "/dumpenv" => $dumperapp;
  81. mount "/selfsrc" => $selfsourceapp;
  82. mount "/" => $indexapp;
  83. };
  84.  
  85. mount "/dumpenv" => $dumperapp;
  86. mount "/selfsrc" => $selfsourceapp;
  87. mount "/" => $indexapp;
  88. };
  89.  
  90. my $runner = Plack::Runner->new;
  91. $runner->parse_options( qw' --host 127.0.0.1 --port 80 ' );
  92. $runner->run( $finalapp );

Report this snippet  

You need to login to post a comment.