From a1cff66f32d1ac7d8b557507acb9ea0195878192 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 29 Jul 2010 22:14:21 +0200 Subject: [PATCH] /examples/ for static files --- scripts/RFID-JSONP-server.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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() }; -- 2.20.1