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 26, 2024
1 parent 02d1984 commit 920be11
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/nodejs/unit-http/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@

'use strict';

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

function createServer (requestHandler) {
function createServer (options, requestHandler) {
if (typeof options === 'function') {
requestHandler = options;
options = {};
} else {
stderr.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 920be11

Please sign in to comment.