tiny_monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello, monks. Finally, I was able to generate a web page using PSGI /Plack. However, I have noticed that my CSS failed to work properly. The css file was on my browser, but it was empty. It seems to me that there is a disconnect between PSGI and the document root (/Library/WebServer/Documents) where I currently keep my static files. Below is a snippet of the code that I used,
#!/usr/bin/perl use strict; use warnings; use diagnostics; use template; my $app = sub { my $html = get_html(); return [ 200, ['Content-Type' => 'text/html'], [$html], ]; }; sub get_html{ # open template file open(my $reader,'< :encoding(UTF-8)',"/library/webserver/documents +/html.html"); my $input; do{$input .= $_} while(<$reader>); # Initialize HTML template my $template = Template->new(); my $vars = {greeting => 'Howdy, Cowboy!',debt => '$1.50',sender => + 'John Wayne'}; my $html; $template->process(\$input,$vars,\$html) || die "Template process failed: ", $template->error(), "\n"; return $html; }
The filename of the above code has a .psgi extension and I ran it using the plackup command. I named my HTML template html.html:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http:/ +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xml:lang='en' xmlns='http://www.w3.org/1999/xhtml' lang='en-US' +> <head> <title>Loan Shark</title> <link rel='stylesheet' type='text/css' href='funky.css' media='' /> </head> <body> <p><span id='try'>[% GET greeting %]</span>, It has come to our attention that your account is in arrears to the sum of [% GET debt %]. Please settle your account before the end of the year or you will face + severe embarrassment. Yours truly, [% sender %]</p> </body> </html>
I used Plack::App::File hoping that my css file would be served properly but it didn't work.
#!/usr/bin/perl use strict; use warnings; use diagnostics; use Plack::App::File; my $app = Plack::App::File->new(root => "/Library/Webserver/Documents" +)->to_app;
After running Plack::App::File, I again checked the browser. The css file contained only a copy of the generated HTML. I tried using Plack::App::Directory and, similarly, yielded the same unsuccessful result. I'd greatly appreciate it if anyone could share an insight into this problem. Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CSS and PSGI
by tangent (Parson) on Aug 19, 2015 at 14:08 UTC | |
by Anonymous Monk on Aug 19, 2015 at 14:28 UTC | |
by tangent (Parson) on Aug 19, 2015 at 14:38 UTC | |
by tiny_monk (Sexton) on Aug 19, 2015 at 15:07 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |