mirror of
https://github.com/hanzonet/explore.git
synced 2026-10-30 18:16:57 +00:00
31 lines
491 B
TypeScript
31 lines
491 B
TypeScript
import type CspDev from 'csp-dev';
|
|
|
|
import config from 'configs/app';
|
|
|
|
const feature = config.features.saveOnGas;
|
|
|
|
export function gasHawk(): CspDev.DirectiveDescriptor {
|
|
if (!feature.isEnabled) {
|
|
return {};
|
|
}
|
|
|
|
const apiOrigin = (() => {
|
|
try {
|
|
const url = new URL(feature.apiUrlTemplate);
|
|
return url.origin;
|
|
} catch (error) {
|
|
return '';
|
|
}
|
|
})();
|
|
|
|
if (!apiOrigin) {
|
|
return {};
|
|
}
|
|
|
|
return {
|
|
'connect-src': [
|
|
apiOrigin,
|
|
],
|
|
};
|
|
}
|