Skip to content

Commit

Permalink
Take options as well as requestListener
Browse files Browse the repository at this point in the history
Closes nginx#1043

Unit-http have not kept up with the signature of nodejs's http package
development. Nodejs allows an optional `options` object to be passed to
the `createServer` function, we didn't. This resulted in function
signature errors when user code that did make use of the options arg
tried to call unit's replaced function.

This change changes the signature to be more in line with how nodejs
does it discarding it and printing a message to stdout.
  • Loading branch information
javorszky committed Jan 25, 2024
1 parent 02d1984 commit 1799414
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/nodejs/unit-http/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@

'use strict';

const util = require('util');
const { stdout } = require('node:process');
const {
Server,
ServerRequest,
ServerResponse,
} = require('./http_server');

function createServer (requestHandler) {
function createServer (options, requestHandler) {
if (typeof options === 'function') {
requestListener = options;
options = {};
} else {
stdout.write('createServer was called with an options object. Unit ignores this for the time being.');
}

return new Server(requestHandler);
}

Expand Down

0 comments on commit 1799414

Please sign in to comment.