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.
In reply to CSS and PSGI by tiny_monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |