Commit 58de165c authored by tom's avatar tom

custom unique function

parent 806d2120
import _unique from 'lodash/uniq';
import appConfig from 'configs/app/config'; import appConfig from 'configs/app/config';
import featuredNetworks from 'lib/networks/featuredNetworks'; import featuredNetworks from 'lib/networks/featuredNetworks';
...@@ -38,6 +36,17 @@ function getMarketplaceAppsLogosOrigins() { ...@@ -38,6 +36,17 @@ function getMarketplaceAppsLogosOrigins() {
return getMarketplaceApps().map(({ logo }) => new URL(logo)); return getMarketplaceApps().map(({ logo }) => new URL(logo));
} }
// we cannot use lodash/uniq in middleware code since it calls new Set() and it'is causing an error in Nextjs
// "Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime"
function unique(array: Array<string | undefined>) {
const set: Record<string, boolean> = {};
for (const item of array) {
item && (set[item] = true);
}
return Object.keys(set);
}
function makePolicyMap() { function makePolicyMap() {
const networkExternalAssets = getNetworksExternalAssets(); const networkExternalAssets = getNetworksExternalAssets();
...@@ -141,7 +150,7 @@ function getCspPolicy() { ...@@ -141,7 +150,7 @@ function getCspPolicy() {
return; return;
} }
const uniqueValues = _unique(value); const uniqueValues = unique(value);
return [ key, uniqueValues.join(' ') ].join(' '); return [ key, uniqueValues.join(' ') ].join(' ');
}) })
.filter(Boolean) .filter(Boolean)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment