feat(license): use strapi.fetch method instead of fetch

This commit is contained in:
nathan-pichon 2023-04-12 19:32:37 +02:00
parent 2e95fd6eaf
commit 25c15f9ebf
No known key found for this signature in database
2 changed files with 11 additions and 8 deletions

View File

@ -105,7 +105,9 @@ const onlineUpdate = async ({ strapi }) => {
};
const license = shouldContactRegistry
? await fetchLicense(ee.licenseInfo.licenseKey, strapi.config.get('uuid')).catch(fallback)
? await fetchLicense({ strapi }, ee.licenseInfo.licenseKey, strapi.config.get('uuid')).catch(
fallback
)
: storedInfo.license;
if (license) {

View File

@ -3,7 +3,6 @@
const fs = require('fs');
const { join } = require('path');
const crypto = require('crypto');
const fetch = require('node-fetch');
const machineId = require('../lib/utils/machine-id');
@ -69,12 +68,14 @@ const throwError = () => {
throw new LicenseCheckError('Could not proceed to the online validation of your license.', true);
};
const fetchLicense = async (key, projectId) => {
const response = await fetch(`https://license.strapi.io/api/licenses/validate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key, projectId, deviceId: machineId() }),
}).catch(throwError);
const fetchLicense = async ({ strapi }, key, projectId) => {
const response = await strapi
.fetch(`https://license.strapi.io/api/licenses/validate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key, projectId, deviceId: machineId() }),
})
.catch(throwError);
const contentType = response.headers.get('Content-Type');