Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Adding CGI .htaccess
Browse files Browse the repository at this point in the history
  • Loading branch information
kentaromiura committed Feb 2, 2014
1 parent 0f78d18 commit 0e94a3c
Show file tree
Hide file tree
Showing 74 changed files with 16,713 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -169,6 +169,12 @@ The .htaccess file works only if present in the root folder you chose for a polp

Every time a callback is invoked, the [event object](https://github.com/WebReflection/polpetta/blob/master/src/htaccess/invokedHtaccess.js) will be sent. If you want to stop a default polpetta behavior, simply use `even.preventDefault()` or `return false` at some point in the callback. This works like DOM Level 3 or DOM 0 events ... as easy as that.

Special cgi-bin .htaccess file
------------------------------
In the *cgi-bin* directory is included a special *.htaccess* file which makes polpetta cgi compliant.
If this htaccess is used any executable file will be executed as a cgi script.
The script will checks if the file has the executable flag for the owner of the file, which should be the most probably scenario and also the safest solution (chmod 500).


Polpetta API
------------
Expand Down
25 changes: 25 additions & 0 deletions cgi-bin/.htaccess
@@ -0,0 +1,25 @@
var cgi = require('cgi')
this.onstaticfile = function (event) {

var
p = event.polpetta,
req = event.request,
res = event.response,
ext = event.ext.toLowerCase(),
fs = require('fs'),
path = require('path'),
stat = fs.statSync(event.file);


if(parseInt(stat.mode.toString(8)[0], 10) & 1){
var exec = cgi(event.file, {cwd : path.dirname(event.file)})
exec(req, res)
event.preventDefault()
}

}

/// for debug purpose
function log(e) {
console.log(e);
}
19 changes: 19 additions & 0 deletions cgi-bin/test.foo
@@ -0,0 +1,19 @@
#!/usr/bin/env perl


print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Polpetta support for proper CGI</title>';
print '</head>';
print '<body>';
print '<h2>Hello Word! This is my first CGI program</h2>';

print '<div>';
print $ENV{'QUERY_STRING'};
print '</div>';
print '<a href="?foo=bar&baz=bak">try with some parameters</a>';
print '</body>';
print '</html>';

1;
84 changes: 84 additions & 0 deletions node_modules/cgi/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

186 changes: 186 additions & 0 deletions node_modules/cgi/cgi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0e94a3c

Please sign in to comment.