-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the initial complete CGI-Node source code.
- Loading branch information
UeiRicho
authored and
UeiRicho
committed
Oct 15, 2014
1 parent
19dce05
commit ee688d2
Showing
17 changed files
with
1,289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Options ExecCGI | ||
SetHandler cgi-script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!"D:/Programs/nodejs/node.exe" | ||
|
||
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2014 UeiRicho | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
@Author: Uei Richo | ||
@Email: [email protected] | ||
This allows us to run CGI-Node directly from the source files without having to build them while in development mode. | ||
*/ | ||
|
||
// Add required modules. | ||
var FS = require('fs'); | ||
|
||
// The list of files to included | ||
var code = ''; | ||
var dir = '../src/' | ||
var files = ['CgiNodeConfig.js', 'CgiNodeContext.js', 'CgiNodeSession.js', 'CgiNodeResponse.js', 'CgiNodeRequest.js', 'CgiNodeParser.js', 'CgiNode.js']; | ||
|
||
// Loop through the files and get the content. | ||
for (var index = 0; index < files.length; index++) code += '\n\n' + FS.readFileSync( dir + files[index] ); | ||
|
||
// Run the source code. | ||
eval(code); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "cgi-node", | ||
"displayName": "cgi-node", | ||
"version": "0.1.0", | ||
"description": "Run Node.js as CGI-Module on any Apache", | ||
"homepage": "http://www.cgi-node.org", | ||
"bugs": "https://code.google.com/p/cgi-node/issues/list", | ||
"author": "Uei Richo <[email protected]>", | ||
"license": "GNU GPL v3", | ||
"repository": { | ||
"type": "svn", | ||
"url": "http://cgi-node.googlecode.com/svn/trunk/" | ||
}, | ||
"main": "./lib/cgi-node", | ||
"bin": { | ||
"cgi-node": "./bin/cgi-node" | ||
}, | ||
"dependencies": { | ||
}, | ||
"engines": { | ||
"node": ">=0.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2014 UeiRicho | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
@Author: Uei Richo | ||
@Email: [email protected] | ||
*/ | ||
|
||
// Add the required modules. | ||
var VM = require('vm'); | ||
var FS = require('fs'); | ||
var URL = require('url'); | ||
var Path = require('path'); | ||
var Crypto = require('crypto'); | ||
var QueryString = require('querystring'); | ||
|
||
// The NodeCGI context. | ||
var cgiNodeContext = null; | ||
|
||
/* | ||
The first thing we are going to do is set up a way to catch any global | ||
exceptions and send them to the client. This is extremely helpful when developing code. | ||
*/ | ||
process.on('uncaughtException', function(error) | ||
{ | ||
// Build the HTML error. | ||
var htmlError = '<br/><div style="color:red"><b>EXCEPTION</b>: ' + error.message + '<i><pre>' + error.stack + '</pre></i></div></br>'; | ||
|
||
// If the CGI context has been created then use the response to send the error | ||
if (cgiNodeContext !== null) cgiNodeContext.response.write( htmlError ); | ||
|
||
// Otherwise send an HTTP header followed by the error. | ||
else process.stdout.write("Content-type: text/html; charset=iso-8859-1\n\n" + htmlError); | ||
}); | ||
|
||
/* | ||
When the process exists make sure to save any session data back to the file. | ||
*/ | ||
process.on('exit', function(code) | ||
{ | ||
// Save the session back to the file. | ||
cgiNodeContext.session.save(); | ||
|
||
// Clean up any sessions that have expired. | ||
cgiNodeContext.session.cleanUp(); | ||
}); | ||
|
||
// Create the CGI context and execute the requested file. | ||
cgiNodeContext = new CgiHttpContext(); | ||
|
||
// Create a callback function that will get called when everything is loaded and ready to go. This will execute the script. | ||
var onReady = function() { cgiNodeContext.include(process.env.PATH_TRANSLATED); }; | ||
|
||
// TODO: remove this when the POST parser is done. | ||
cgiNodeContext.request.method = 'GET'; | ||
|
||
// If the HTTP method is a 'POST' then read the post data. Otherwise process is ready. | ||
if (cgiNodeContext.request.method != 'POST') onReady(); | ||
else cgiNodeContext.request.readPost(onReady); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2014 UeiRicho | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
@Author: Uei Richo | ||
@Email: [email protected] | ||
This is the global configuration object for CgiNode. | ||
NOTE: It is not in a JSON file because we want to compile it directly within the final cig-node.js file to optimize load time. | ||
*/ | ||
var CgiNodeConfig = | ||
{ | ||
Version: '0.2', | ||
|
||
StartTag: '<?', // Not being used yet. | ||
EndTag: '<?', // Not being used yet. | ||
|
||
ScriptExtensions: ['.js'], // Not being used yet. | ||
|
||
EmbededScriptExtensions: ['.jss'], // Not being used yet. | ||
|
||
SessionCookie: 'CGI-NODE-SESSIONID', | ||
SessionTimeOut: 15*60, // 15 minutes | ||
SessionPath: 'D:/Programs/nodejs/sessions/' | ||
}; |
Oops, something went wrong.