Skip to content

Commit 36b726c

Browse files
committed
Merge pull request #3 from robertgroh/master
Adds an integration test and some badge to the readme
2 parents 5c11d3a + 3f6b4ba commit 36b726c

File tree

8 files changed

+363
-20
lines changed

8 files changed

+363
-20
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
#npm
12
node_modules
3+
npm-debug.log
4+
5+
#project files of JetBrains IDEs
6+
.idea
7+
8+
#Istanbul coverage folder
9+
coverage

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
#git repo
2+
example
13
test
4+
5+
#npm
26
node_modules
7+
8+
#Codestyle rules
9+
.jscsrc
10+
11+
#continous integration
12+
.travis.yml

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- '0.10'
4+
- "0.12"
5+
- "iojs"
6+
after_script:
7+
- npm run coveralls

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
node-fastcgi
22
============
33

4+
[![Build Status](https://api.travis-ci.org/robertgroh/node-fastcgi.svg?branch=master)](https://travis-ci.org/robertgroh/node-fastcgi)
5+
[![Coverage Status](https://coveralls.io/repos/robertgroh/node-fastcgi/badge.svg?branch=master)](https://coveralls.io/r/robertgroh/node-fastcgi?branch=master)
6+
[![Dependency Status](https://gemnasium.com/robertgroh/node-fastcgi.svg)](https://gemnasium.com/robertgroh/node-fastcgi)
7+
[![devDependency Status](https://david-dm.org/robertgroh/node-fastcgi/dev-status.svg)](https://david-dm.org/robertgroh/node-fastcgi#info=devDependencies)
8+
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
9+
10+
[![NPM](https://nodei.co/npm/node-fastcgi.png?downloads=true)](https://nodei.co/npm/node-fastcgi/)
11+
412
This module is a replacement for node's http module (server only). It can be used to build FastCGI applications or to convert existing node applications to FastCGI.
513

6-
The implementation is fully compliant with FastCGI 1.0 Specification (http://www.fastcgi.com/drupal/node/6?q=node/22)
14+
The implementation is fully compliant with [FastCGI 1.0 Specification](http://www.fastcgi.com/drupal/node/6?q=node/22).
15+
716

817
Example
918
-------
File renamed without changes.

example/integration.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Copyright Robert Groh and other contributors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the 'Software'), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
'use strict';
23+
24+
var path = require('path')
25+
, fcgiFramework = require('../index.js'); //this we want to test
26+
27+
var port = 8080;
28+
var socketPath = path.join(__dirname, 'echoServer');
29+
try {
30+
require('fs').unlinkSync(socketPath);
31+
} catch (err) {
32+
//ignore if file doesn't exists
33+
if(err.code !== 'ENOENT') {
34+
throw err;
35+
}
36+
}
37+
38+
function answerWithError(res, err) {
39+
res.writeHead(500, { 'Content-Type': 'text/plain; charset=utf-8', 'Content-Length': err.stack.length });
40+
res.end(err.stack + '\n');
41+
}
42+
43+
fcgiFramework.createServer(
44+
function echo(req, res) {
45+
var requestData;
46+
47+
req.on('data', function (data) {
48+
requestData = requestData + data;
49+
});
50+
51+
req.on('complete', function writeReqAsJson() {
52+
var echoData
53+
, size;
54+
55+
try {
56+
var strippedRequest = require('lodash').omit(req, 'connection', 'buffer', 'socket', '_events', '_readableState', 'data');
57+
strippedRequest.data = requestData;
58+
59+
echoData = JSON.stringify(strippedRequest, null, 4); //hopefully only here will an error be thrown
60+
size = Buffer.byteLength(echoData, 'utf8');
61+
res.writeHead(
62+
200,
63+
{
64+
'Content-Type': 'application/json; charset=utf-8',
65+
'Content-Length': size
66+
}
67+
);
68+
res.end(echoData);
69+
} catch (err) {
70+
answerWithError(res, err);
71+
}
72+
});
73+
74+
req.on('error', answerWithError.bind(undefined, res));
75+
}
76+
).listen(socketPath, function cgiStarted(err) {
77+
console.log('cgi app listen on socket:' + socketPath);
78+
if (err) {
79+
throw err;
80+
} else {
81+
var http = require('http');
82+
var fcgiHandler = require('fcgi-handler');
83+
84+
var server = http.createServer(function (req, res) {
85+
fcgiHandler.connect({path: socketPath}, function (err, fcgiProcess) {
86+
if (err) {
87+
throw err;
88+
} else {
89+
//route all request to fcgi application
90+
fcgiProcess.handle(req, res, {/*empty Options*/});
91+
}
92+
});
93+
});
94+
server.listen(port);
95+
}
96+
});
97+
98+
99+

package.json

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
{
2-
"name": "node-fastcgi",
3-
"version": "0.1.9",
4-
"description": "Create FastCGI applications in node. Near drop-in replacement for node's http module.",
5-
"keywords": [ "fcgi", "fastcgi", "server" ],
6-
"homepage": "https://github.com/fbbdev/node-fastcgi",
7-
"author": {
8-
"name": "Fabio Massaioli",
9-
"email": "[email protected]"
10-
},
11-
"license": "MIT",
12-
"main": "./index.js",
13-
"engines": { "node": ">= 0.10.5" },
14-
"dependencies": {
15-
"fastcgi-stream": ">= 0.1.3"
16-
},
17-
"repository" : {
18-
"type" : "git",
19-
"url" : "https://github.com/fbbdev/node-fastcgi.git"
20-
}
2+
"name": "node-fastcgi",
3+
"version": "0.1.9",
4+
"description": "Create FastCGI applications in node. Near drop-in replacement for node's http module.",
5+
"keywords": [ "fcgi", "fastcgi", "server" ],
6+
"homepage": "https://github.com/fbbdev/node-fastcgi",
7+
"author": {
8+
"name": "Fabio Massaioli",
9+
"email": "[email protected]"
10+
},
11+
"license": "MIT",
12+
"main": "./index.js",
13+
"engines": { "node": ">= 0.10.5" },
14+
"dependencies": {
15+
"fastcgi-stream": ">= 0.1.3"
16+
},
17+
"repository" : {
18+
"type" : "git",
19+
"url" : "https://github.com/fbbdev/node-fastcgi.git"
20+
},
21+
"devDependencies": {
22+
"chai": "^2.3.0",
23+
"coveralls": "^2.11.2",
24+
"fcgi-handler": "git+https://github.com/aredridel/fcgi-handler.git#afe16eae560280d5dd84241d0c45e5db0f939d25",
25+
"istanbul": "^0.3.14",
26+
"lodash": "^3.9.1",
27+
"mocha": "^2.2.5",
28+
"mocha-lcov-reporter": "0.0.2",
29+
"request": "^2.55.0"
30+
},
31+
"scripts": {
32+
"test": "./node_modules/.bin/mocha ./test/mocha/integration",
33+
"coveralls": "./node_modules/.bin/istanbul cover --report lcovonly ./node_modules/mocha/bin/_mocha -- ./test/mocha/integration && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
34+
}
2135
}

0 commit comments

Comments
 (0)