import { useGlobSetting } from '../setting';

let initialFlag = false;
export function useWebSecurityPolicy() {
  if (window && window.document && window.document.documentElement) {
    const { securityPolicy } = useGlobSetting();
    if (securityPolicy === 'true' && !initialFlag) {
      const meta = document.createElement('meta');
      meta.setAttribute('http-equiv', 'Content-Security-Policy');
      meta.setAttribute('content', 'upgrade-insecure-requests');
      const container = document.querySelector('head');
      container?.prepend(meta);
      initialFlag = true;
    }
  }
}
