Skip to content

Instantly share code, notes, and snippets.

@zwetan
Last active August 29, 2015 14:08
Show Gist options
  • Save zwetan/a3fef68ac32bd4971c76 to your computer and use it in GitHub Desktop.
Save zwetan/a3fef68ac32bd4971c76 to your computer and use it in GitHub Desktop.
CGI example 2
/* build:
import redbean.*;
import shell.FileSystem;
compile( "src/index.as" );
if( FileSystem.exists( "index.abc" ) )
{
FileSystem.remove( "index.abc" );
}
FileSystem.move( "src/index.abc", "index.abc", true );
projector( "index", true, OS.linux64, [ "index.abc" ] );
FileSystem.move( "index", "index.cgi", true );
*/
import shell.Program;
import shell.Runtime;
var body:XML = <body>
<h1>AAA</h1>
<p>BBB</p>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>;
var table_line:XML = <tr>
<td>CCC</td>
<td>DDD</td>
</tr>;
trace( "Content-type: text/html\n\n" );
body.h1 = "Hello, World.";
body.p = "I'm " + Runtime.description + " running on " + Runtime.platform + " " + ( Runtime.is64bit() ? "64-bit": "32-bit" );
var i:uint;
var len:uint = Program.environ.length;
var line:String;
var newline:XML;
for( i = 0 ; i < len; i++ )
{
line = Program.environ[i];
//trace( "line = " + line );
var pos:int = line.indexOf( "=" );
newline = table_line.copy();
newline.td[0] = line.substr( 0, pos );
newline.td[1] = line.substring( pos+1 );
body.table.tbody.appendChild( newline );
}
trace( "<!DOCTYPE html>" );
trace( "<html>" );
trace( "<head>" );
trace( "<title>" + "RedTamarin running as CGI" + "</title>" );
trace( "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" );
trace( "<!-- Bootstrap -->" );
trace( "<link href=\"//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css\" rel=\"stylesheet\" media=\"screen\">" );
trace( "<script src=\"//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>" );
trace( "<script src=\"//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js\"></script>" );
trace( "</head>" );
trace( body.toXMLString() );
trace( "</html>" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment