mirror of
https://github.com/strapi/strapi.git
synced 2026-01-06 04:03:25 +00:00
feat(fetch): add internal fetch method in Strapi
Add support to proxy configuration
This commit is contained in:
parent
9f20e8470e
commit
2e95fd6eaf
@ -27,6 +27,7 @@ const createCustomFields = require('./services/custom-fields');
|
||||
const createContentAPI = require('./services/content-api');
|
||||
const createUpdateNotifier = require('./utils/update-notifier');
|
||||
const createStartupLogger = require('./utils/startup-logger');
|
||||
const createStrapiFetch = require('./utils/fetch');
|
||||
const { LIFECYCLES } = require('./utils/lifecycles');
|
||||
const ee = require('./utils/ee');
|
||||
const contentTypesRegistry = require('./core/registries/content-types');
|
||||
@ -118,6 +119,7 @@ class Strapi {
|
||||
this.telemetry = createTelemetry(this);
|
||||
this.requestContext = requestContext;
|
||||
this.customFields = createCustomFields(this);
|
||||
this.fetch = createStrapiFetch(this);
|
||||
|
||||
createUpdateNotifier(this).notify();
|
||||
|
||||
|
||||
19
packages/core/strapi/lib/utils/fetch.js
Normal file
19
packages/core/strapi/lib/utils/fetch.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const fetch = require('node-fetch');
|
||||
const HttpsProxyAgent = require('https-proxy-agent');
|
||||
|
||||
function createStrapiFetch(strapi) {
|
||||
const { proxy } = strapi.config.get('server');
|
||||
const defaultOptions = {};
|
||||
|
||||
if (proxy) {
|
||||
defaultOptions.agent = new HttpsProxyAgent(proxy);
|
||||
}
|
||||
|
||||
return (url, options) => {
|
||||
return fetch(url, { ...defaultOptions, ...options });
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = createStrapiFetch;
|
||||
@ -109,6 +109,7 @@
|
||||
"fs-extra": "10.0.0",
|
||||
"glob": "7.2.0",
|
||||
"http-errors": "1.8.1",
|
||||
"https-proxy-agent": "5.0.1",
|
||||
"inquirer": "8.2.5",
|
||||
"is-docker": "2.2.1",
|
||||
"koa": "2.13.4",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user