Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
Created December 20, 2010 03:01
Show Gist options
  • Save drewlesueur/747964 to your computer and use it in GitHub Desktop.
Save drewlesueur/747964 to your computer and use it in GitHub Desktop.
Example of using the express framework as cgi instead of running on a node server!
#!/usr/bin/env coffee
cgi = require "/root/sites/coffee-cgi/cgi"
sys = require "sys"
http = require "http"
http.IncomingMessage = cgi.Request
http.ServerResponse = cgi.Response
connect = require "connect"
express = require "express"
connect.Server.prototype.listen = (port, host) ->
express.Server.prototype.listen = () ->
this.registerErrorHandlers()
app = express.createServer()
app.use (req, res, next) ->
req.expresscgi = "just an an example of using `use` !"
next()
app.get "/test.cs", (req, res) ->
res.send req.expresscgi
#app.emit 'request', new cgi.Request(), new cgi.Response()
app.emit 'request', new http.IncomingMessage(), new http.ServerResponse()
# other tries below
#app.emit('connection', new Stream())
#app.emit 'request', handler
#app.emit 'request', new http.ServerResponse()
#app.handle({},{})
#for x in app.stack
#x.handle()
@drewlesueur
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment