Changeset 23352

Show
Ignore:
Timestamp:
11/12/08 17:08:00 (5 years ago)
Author:
mattn
Message:

静的ファイル処理を追加してみた。
もしかしたら config に static_url みたいなので許可する URL を指定させた方が良かったかも。

Location:
lang/perl/MENTA/trunk
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/MENTA/trunk/app/tmpl/index.html

    r23336 r23352  
    11<!doctype html> 
     2<html> 
     3<head> 
    24<title><%= config()->{application}->{title} %></title> 
     5<link rel="stylesheet" type="text/css" href="/static/style-sites.css"/> 
     6</head> 
     7<body> 
     8<h1><%= config()->{application}->{title} %></h1> 
    39<p><%= localtime time %></p> 
     10</body> 
     11</html> 
  • lang/perl/MENTA/trunk/lib/MENTA.pm

    r23336 r23352  
    4949        } 
    5050 
    51         { 
     51        my $static_file = $ENV{PATH_INFO} || ''; 
     52        $static_file =~ s!^/*!app/!g; 
     53        if ($static_file !~ /index\.cgi/ && -f $static_file) { 
     54            if (open my $fh, '<', $static_file) { 
     55                printf "Content-Type: %s\n\n", guess_mime_type($static_file); 
     56                while(<$fh>) { print $_ } 
     57                close $fh; 
     58            } else { 
     59                die "ファイルが見つかりません"; 
     60            } 
     61        } else { 
    5262            my $mode = $REQ->{mode} || 'index'; 
    5363            my $meth = "do_$mode"; 
     
    94104} 
    95105 
     106sub guess_mime_type { 
     107    my $ext = shift; 
     108    $ext =~ s/.+\.(.+)$/$1/; 
     109 
     110    # TODO should be moved to other. 
     111    my $mime_map = { 
     112            css => 'text/css', 
     113            txt => 'text/plain', 
     114        }; 
     115        $mime_map->{$ext} || 'application/octet-stream'; 
     116} 
     117 
    961181;