puffnfresh / node-cgi Goto Github PK
View Code? Open in Web Editor NEWA CGI adaptor for node.js
Home Page: http://brianmckenna.org/blog/nodejs_via_cgi
License: MIT License
A CGI adaptor for node.js
Home Page: http://brianmckenna.org/blog/nodejs_via_cgi
License: MIT License
Hi pufuwozu, i think the latest node.js may cause some issues for you.
hope this is useful
ngo
I took your project out for a spin because I wanted to use node.js in a shared-host environment, and lured by the promise that I could just replace the http object with node-cgi, thought to try it out. I wrote a script that needed to handle POST data. And it didn't work.
After doing a bit of research on the problem, I learned that when the http object calls a listener, the request object it passes in is a Readable Stream; the stream contains the body of the request (if one is present). What node-cgi does is creates a property Object.
I got myself unstuck by rewriting Request in cgi.js:
var Request = function() {
var req = process.stdin;
req.method = process.env['REQUEST_METHOD'];
req.headers = {
'host': process.env['HTTP_HOST'],
'user-agent': process.env['HTTP_USER_AGENT']
};
req.url = process.env['REQUEST_URI'];
return req
};
That code shouldn't go into your cgi class as is without some more work. It's not obvious to me (yet) how to make a copy of process.stdin so that I could add other properties safely.
This code (as well as the original) also lacks all of the headers that might have been passed in from process.env. This would be problematic, for example, if I wanted to add Basic Auth support to my script.
Will you be spending some time making the Request object a bit more powerful?
Would you run npm publish
in your node-cgi repo? I figure the author should be the one that publishes this library. Once that is done, I can just list it as a dependency in my project and a npm install
will pull in this last library for me.
Thanks!
How do you get POST data?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.