From: Dobrica Pavlinusic Date: Thu, 29 Jul 2010 20:14:21 +0000 (+0200) Subject: /examples/ for static files X-Git-Tag: RFID-Biblio-0.02~104 X-Git-Url: http://git.rot13.org/?p=Biblio-RFID.git;a=commitdiff_plain;h=a1cff66f32d1ac7d8b557507acb9ea0195878192;hp=18a6cd17b837fae001b0a44fe6bbc9f53611e2a9 /examples/ for static files --- diff --git a/scripts/RFID-JSONP-server.pl b/scripts/RFID-JSONP-server.pl index 7877fca..0428c51 100755 --- a/scripts/RFID-JSONP-server.pl +++ b/scripts/RFID-JSONP-server.pl @@ -70,6 +70,21 @@ sub http_server { if ( $path eq '/' ) { print $client "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n$index_html"; + } elsif ( $path =~ m{^/(examples/.+)} ) { + $path = $1; # FIXME prefix with dir for installation + my $size = -s $path; + warn "static $path $size bytes\n"; + my $content_type = 'text/plain'; + $content_type = 'application/javascript' if $path =~ /\.js/; + print $client "HTTP/1.0 200 OK\r\nContent-Type: $content_type\r\nContent-Length: $size\r\n\r\n"; + { + local $/ = undef; + open(my $fh, '<', $path) || die "can't open $path: $!"; + while(<$fh>) { + print $client $_; + } + close($fh); + } } elsif ( $method =~ m{/scan} ) { my $tags = $rfid->scan; my $json = { time => time() };