1

I have the following code:

export const makeHttpHelper = function (authToken: string) {

  return function ($data: any, optz: object, cb: VoidFn) {

    const data = JSON.stringify($data || '\n');

    const opts : http.Request.options = Object.assign({   /// <<<< here <<<<<<
        method: 'POST',
        host: process.env.OPENSHIFT_NODEJS_IP || 'localhost',
        port: process.env.OPENSHIFT_NODEJS_PORT || '3040',
        agent: false,
        headers: getHeaders()
      }, optz);

    const req = http.request(opts, function (res) {

      if (res.statusCode > 202) {
        log.error(`res status => ${res.statusMessage}, ${res.statusCode}, req url => ${opts.url || opts.path}`);
      }
      else {
        log.info(`res status => ${res.statusMessage}, ${res.statusCode}, req url => ${opts.url || opts.path}`);
      }

     // ....
});

....the problem is that http.Request.options is not correct. Does anyone know what the right type is for the options object that goes as the first argument to http.request()?

1 Answer 1

2

http.Request.options is not correct

Correct one is http.RequestOptions.

Fixed :

import * as http from 'http';
const options: http.RequestOptions = { // Fixed

}
http.request(options, /* other */)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.