节点-定义请求默认值不起作用

时间:2019-07-19 13:24:54

标签: javascript node.js

我试图定义通用请求默认值,但是它似乎不起作用,因为只有“ body”和“ url”成为请求结构的一部分。

代码如下:

const { URL } = require('url');
const request = require('request-promise-native');
const config = require('./config');

let GIT_API_URL = new URL(config.CI_PROJECT_URL);
GIT_API_URL.pathname = '/v4/api';
GIT_API_URL = GIT_API_URL.toString();

const gitLabDefaultRequest = request.defaults({
  headers: {
    'Content-Type': 'application/json',
    'PRIVATE-TOKEN': config.GIT_API_ACCESS_TOKEN,
  },
  json: true,
  simple: true,
  timeout: 15000,
  resolveWithFullResponse: true,
});

async function createCommit(commitRequestBody) {
  const options = {
    url: `${GIT_API_URL}/projects/${config.PROJECT_ID}/repository/commits`,
    body: commitRequestBody,
  };

  const response = await gitLabDefaultRequest.post(options);
  return response;
}

请告知。

0 个答案:

没有答案