Difference between revisions of "Namecoin SPA"

From Organic Design wiki
(perl part)
 
(html part)
Line 10: Line 10:
 
my $c;
 
my $c;
 
while($c=$s->accept()){
 
while($c=$s->accept()){
  next if my $pid = fork;
+
next if my $pid = fork;
  die "fork - $!\n" unless defined $pid;
+
die "fork - $!\n" unless defined $pid;
  my $i;
+
my $i;
  while(<$c>){last if/^\r\n$/;$i.=$_;}
+
while(<$c>){last if/^\r\n$/;$i.=$_;}
  $_=$i=~/^GET (\/[a-z0-9]+)/?`namecoind name_show d$1`:`namecoind name_show d/subjective`;
+
$_=$i=~/^GET (\/[a-z0-9]+)/?`namecoind name_show d$1`:`namecoind name_show d/subjective`;
  $_=/"value"\s*:\s*"(.*?[^\\])"/s?$1:":(";
+
$_=/"value"\s*:\s*"(.*?[^\\])"/s?$1:":(";
  s/\\"/"/g;
+
s/\\"/"/g;
  s/\\n/\n/g;
+
s/\\n/\n/g;
  my $l=length $_;
+
my $l=length $_;
  select $c;
+
select $c;
  $|=1;
+
$|=1;
  print $c "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=UTF-8\nConnection: Keep-Alive\nKeep-Alive: timeout=15, max=100\nContent-Length: $l\n\n$_\r\n\r\n";
+
print $c "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=UTF-8\n";
  close($c);
+
print $c "Connection: Keep-Alive\nKeep-Alive: timeout=15, max=100\nContent-Length: $l\n\n$_\r\n\r\n";
  exit(fork);
+
close($c);
 +
exit(fork);
 
}
 
}
 
continue{close($c);kill CHLD=>-$$;}</perl>}}
 
continue{close($c);kill CHLD=>-$$;}</perl>}}
Line 29: Line 30:
  
 
If any nodes are requested they'll usually just be some JSON text defining the nodes DNS connections to other IP addresses or domains. The default node's content is however not JSON, but a small XHTML document. This loads a simple container page that loads some useful libraries such as [[jQuery]] and jQueryUI, and then requests any node specified in the hash fragment of the URL by Ajax.
 
If any nodes are requested they'll usually just be some JSON text defining the nodes DNS connections to other IP addresses or domains. The default node's content is however not JSON, but a small XHTML document. This loads a simple container page that loads some useful libraries such as [[jQuery]] and jQueryUI, and then requests any node specified in the hash fragment of the URL by Ajax.
 +
{{code|<xml><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 +
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
 +
<head>
 +
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 +
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
 +
<script type="text/javascript" src="http://code.jquery.com/ui/jquery-ui-git.js"></script>
 +
<link rel="stylesheet" href="http://code.jquery.com/ui/jquery-ui-git.css" media="screen" />
 +
</head>
 +
<body>
 +
<script>
 +
function hash() {
 +
var h=window.location.hash.substr(1);
 +
if(h){
 +
$.ajax({
 +
type: "GET",
 +
url: "/"+h,
 +
success: function(d) { alert(d) }
 +
});
 +
} else alert("no hash");
 +
}
 +
$(window).bind("hashchange", hash);
 +
hash();
 +
</script>
 +
</body>
 +
</html></xml>}}

Revision as of 20:52, 25 August 2012

I'm making a Single Page Application which exists entirely inside the Namecoin network's name:value storage system. Values can only be a maximum size of one kilobyte, so the boot-strapping has to be very modular.

The root node contains a tiny Perl script which when executed on the command-line listens for incoming HTTP connections on port 2012. The request is treated as a requst for the content of a Namecoin node, but if there is no name specified, then a default node's content is returned.

{{{1}}}


If any nodes are requested they'll usually just be some JSON text defining the nodes DNS connections to other IP addresses or domains. The default node's content is however not JSON, but a small XHTML document. This loads a simple container page that loads some useful libraries such as jQuery and jQueryUI, and then requests any node specified in the hash fragment of the URL by Ajax.

<xml><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

</xml>