mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-10 04:45:05 +00:00
fix(@embark/ipfs): Update IPFS config CORS with default config
Check if IPFS config has `API.HTTPHeaders.Access-Control-Allow-Origin` before attempting to update it. `ipfs init` produces a default configuration without a `API.HTTPHeaders.Access-Control-Allow-Origin` element in the JSON. This caused an error to be thrown when attempting to update the IPFS config to provide CORS values.
This commit is contained in:
parent
05803fcf42
commit
518d319917
@ -4,6 +4,8 @@ const constants = require('../../constants');
|
|||||||
|
|
||||||
let ipfsProcess; // eslint-disable-line no-unused-vars
|
let ipfsProcess; // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
|
const IPFS_DEFAULT_CONFIG_ERROR = "API.HTTPHeaders key has no attributes";
|
||||||
|
|
||||||
class IPFSProcess extends ProcessWrapper {
|
class IPFSProcess extends ProcessWrapper {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super();
|
super();
|
||||||
@ -64,12 +66,18 @@ class IPFSProcess extends ProcessWrapper {
|
|||||||
|
|
||||||
// check cors config before updating if needed
|
// check cors config before updating if needed
|
||||||
self.getCorsConfig((err, config) => {
|
self.getCorsConfig((err, config) => {
|
||||||
if(err){
|
if(err && err.indexOf(IPFS_DEFAULT_CONFIG_ERROR) === -1){
|
||||||
return console.error('Error getting IPFS CORS config: ', err);
|
return console.error('Error getting IPFS CORS config: ', err);
|
||||||
}
|
}
|
||||||
let corsConfig = new Set(JSON.parse(config));
|
let needsUpdate = false;
|
||||||
// test to ensure we have all cors needed
|
try {
|
||||||
const needsUpdate = !self.cors.every(address => corsConfig.has(address));
|
let corsConfig = new Set(JSON.parse(config));
|
||||||
|
// test to ensure we have all cors needed
|
||||||
|
needsUpdate = !self.cors.every(address => corsConfig.has(address));
|
||||||
|
}
|
||||||
|
catch (_e) {
|
||||||
|
needsUpdate = true;
|
||||||
|
}
|
||||||
if(needsUpdate){
|
if(needsUpdate){
|
||||||
// update IPFS cors config
|
// update IPFS cors config
|
||||||
return self.updateCorsConfig(err => {
|
return self.updateCorsConfig(err => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user