Skip to content

Commit a5f7b8e

Browse files
committed
Make examples and tests compatible with the new implementation
1 parent b1770f9 commit a5f7b8e

File tree

3 files changed

+36
-45
lines changed

3 files changed

+36
-45
lines changed

example/fileServer.js

100644100755
Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
/**
44
* Copyright (c) 2016 Fabio Massaioli and other contributors
55
*
6-
* Code from Node http module:
7-
* Copyright Joyent, Inc. and other Node contributors
8-
*
96
* Permission is hereby granted, free of charge, to any person obtaining a copy of
107
* this software and associated documentation files (the "Software"), to deal in
118
* the Software without restriction, including without limitation the rights to
@@ -30,55 +27,51 @@ var fcgi = require('../index.js'),
3027
fs = require('fs'),
3128
util = require('util');
3229

33-
var count = 0;
34-
35-
function s(obj) {
36-
return util.inspect(obj);
30+
function log(msg) {
31+
fs.appendFileSync('fileServer.log', msg);
3732
}
3833

3934
fcgi.createServer(function (req, res) {
40-
count += 1;
41-
42-
req.on('complete', function () {
43-
var path = req.url.slice(1);
44-
fs.stat(path, function (err, stat) {
45-
if (err) {
46-
res.writeHead(500, {
47-
'Content-Type': 'text/plain; charset=utf-8',
48-
'Content-Length': err.stack.length
49-
});
50-
res.end(err.stack + '\n');
51-
} else {
52-
var stream = fs.createReadStream(path);
53-
res.writeHead(200, {
54-
'Content-Type': 'application/octet-stream',
55-
'Content-Length': stat.size
56-
});
57-
stream.pipe(res);
58-
}
59-
});
35+
var path = req.url.slice(1);
36+
fs.stat(path, function (err, stat) {
37+
if (err) {
38+
res.writeHead(500, {
39+
'Content-Type': 'text/plain; charset=utf-8',
40+
'Content-Length': err.stack.length
41+
});
42+
res.end(err.stack + '\n');
43+
} else {
44+
var stream = fs.createReadStream(path);
45+
res.writeHead(200, {
46+
'Content-Type': 'application/octet-stream',
47+
'Content-Length': stat.size
48+
});
49+
stream.pipe(res);
50+
}
6051
});
61-
}).listen();
52+
}).listen(function () {
53+
log('Listening\n');
54+
});
6255

6356
process.on('uncaughtException', function (err) {
64-
fs.appendFileSync('test.log', err.stack + '\n\n');
57+
log(err.stack + '\n\n');
6558
process.exit(1);
6659
});
6760

6861
process.on('exit', function () {
69-
fs.appendFileSync('test.log', 'Exit - Uptime:' + process.uptime() + '\n\n');
62+
log('Exit - Uptime:' + process.uptime() + '\n\n');
7063
});
7164

7265
process.on('SIGTERM', function () {
73-
fs.appendFileSync('test.log', 'SIGTERM\n');
66+
log('SIGTERM\n');
7467
process.exit(0);
7568
});
7669

7770
process.on('SIGINT', function () {
78-
fs.appendFileSync('test.log', 'SIGINT\n');
71+
log('SIGINT\n');
7972
process.exit(0);
8073
});
8174

8275
process.on('SIGUSR1', function () {
83-
fs.appendFileSync('test.log', 'SIGUSR1\n');
76+
log('SIGUSR1\n');
8477
});

example/integration.js

100644100755
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
/**
44
* Copyright (c) 2016 Fabio Massaioli, Robert Groh and other contributors
55
*
6-
* Code from Node http module:
7-
* Copyright Joyent, Inc. and other Node contributors
8-
*
96
* Permission is hereby granted, free of charge, to any person obtaining a copy of
107
* this software and associated documentation files (the 'Software'), to deal in
118
* the Software without restriction, including without limitation the rights to
@@ -56,11 +53,12 @@ fcgiFramework.createServer(function echo(req, res) {
5653
requestData = requestData + data;
5754
});
5855

59-
req.on('complete', function writeReqAsJson() {
56+
req.on('end', function writeReqAsJson() {
6057
var echoData, size;
6158

6259
try {
63-
var strippedRequest = require('lodash').omit(req, 'connection', 'buffer', 'socket', '_events', '_readableState', 'data');
60+
var strippedRequest = require('lodash').omit(req, 'client', 'connection', 'buffer', 'socket', '_events', '_readableState', 'data');
61+
strippedRequest.cgiParams = req.socket.params;
6462
strippedRequest.data = requestData;
6563

6664
echoData = JSON.stringify(strippedRequest, null, 4); //hopefully only here will an error be thrown
@@ -77,7 +75,7 @@ fcgiFramework.createServer(function echo(req, res) {
7775

7876
req.on('error', answerWithError.bind(undefined, res));
7977
}).listen(socketPath, function cgiStarted(err) {
80-
console.log('cgi app listen on socket:' + socketPath);
78+
console.log('cgi app listen on socket: ' + socketPath);
8179
if (err) {
8280
throw err;
8381
} else {
@@ -96,6 +94,8 @@ fcgiFramework.createServer(function echo(req, res) {
9694
}
9795
});
9896
});
99-
server.listen(port);
97+
server.listen(port, function() {
98+
console.log('http server listening on port: ' + port);
99+
});
100100
}
101101
});

test/mocha/integration/echo.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/**
22
* Copyright (c) 2016 Fabio Massaioli, Robert Groh and other contributors
33
*
4-
* Code from Node http module:
5-
* Copyright Joyent, Inc. and other Node contributors
6-
*
74
* Permission is hereby granted, free of charge, to any person obtaining a copy of
85
* this software and associated documentation files (the 'Software'), to deal in
96
* the Software without restriction, including without limitation the rights to
@@ -63,8 +60,9 @@ describe('echo Server', function setup() {
6360
});
6461

6562
req.on('end', function writeReqAsJson() {
66-
var echoData, size, strippedRequest = require('lodash').omit(req, 'connection', 'buffer', 'socket', '_events', '_readableState', 'data');
63+
var echoData, size, strippedRequest = require('lodash').omit(req, 'client', 'connection', 'buffer', 'socket', '_events', '_readableState', 'data');
6764

65+
strippedRequest.cgiParams = req.socket.params;
6866
strippedRequest.data = requestData;
6967

7068
try {
@@ -168,7 +166,7 @@ describe('echo Server', function setup() {
168166

169167
var echo = JSON.parse(body);
170168
expect(echo).to.have.deep.property('cgiParams.PATH_INFO', requestPath);
171-
expect(echo).to.have.deep.property('_queryString', 'a=b&ca=d');
169+
expect(echo).to.have.deep.property('url', requestPath + '?a=b&ca=d');
172170

173171
done(err);
174172
});

0 commit comments

Comments
 (0)