Skip to content
Snippets Groups Projects
Select Git revision
  • set-sast-config-1
  • master default
  • msauth
  • email-template
  • 1.4.20 protected
  • 1.4.19 protected
  • 1.4.18 protected
  • 1.4.17 protected
  • 1.4.16 protected
  • 1.4.15 protected
  • 1.4.14 protected
  • 1.4.13 protected
  • 1.4.12 protected
  • 1.4.11-3 protected
  • 1.4.11-2 protected
  • 1.4.11 protected
  • 1.4.10 protected
  • 1.4.9 protected
  • 1.4.8 protected
  • 1.4.7 protected
  • 1.4.6 protected
  • 1.4.5 protected
  • 1.4.4 protected
  • 1.4.3 protected
24 results

environment.ps1.example

Blame
  • serviceWorker.ts 5.17 KiB
    // This optional code is used to register a service worker.
    // register() is not called by default.
    
    // This lets the app load faster on subsequent visits in production, and gives
    // it offline capabilities. However, it also means that developers (and users)
    // will only see deployed updates on subsequent visits to a page, after all the
    // existing tabs open on the page have been closed, since previously cached
    // resources are updated in the background.
    
    // To learn more about the benefits of this model and instructions on how to
    // opt-in, read https://bit.ly/CRA-PWA
    
    const isLocalhost = Boolean(
      window.location.hostname === 'localhost' ||
        // [::1] is the IPv6 localhost address.
        window.location.hostname === '[::1]' ||
        // 127.0.0.0/8 are considered localhost for IPv4.
        window.location.hostname.match(
          /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
        )
    );
    
    type Config = {
      onSuccess?: (registration: ServiceWorkerRegistration) => void;
      onUpdate?: (registration: ServiceWorkerRegistration) => void;
    };
    
    export function register(config?: Config) {
      if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
        // The URL constructor is available in all browsers that support SW.
        const publicUrl = new URL(
          process.env.PUBLIC_URL,
          window.location.href
        );
        if (publicUrl.origin !== window.location.origin) {
          // Our service worker won't work if PUBLIC_URL is on a different origin
          // from what our page is served on. This might happen if a CDN is used to
          // serve assets; see https://github.com/facebook/create-react-app/issues/2374
          return;
        }
    
        window.addEventListener('load', () => {
          const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
    
          if (isLocalhost) {
            // This is running on localhost. Let's check if a service worker still exists or not.
            checkValidServiceWorker(swUrl, config);
    
            // Add some additional logging to localhost, pointing developers to the
            // service worker/PWA documentation.
            navigator.serviceWorker.ready.then(() => {
              console.log(
                'This web app is being served cache-first by a service ' +
                  'worker. To learn more, visit https://bit.ly/CRA-PWA'
              );
            });
          } else {
            // Is not localhost. Just register service worker
            registerValidSW(swUrl, config);
          }
        });
      }
    }
    
    function registerValidSW(swUrl: string, config?: Config) {
      navigator.serviceWorker
        .register(swUrl)
        .then(registration => {
          registration.onupdatefound = () => {
            const installingWorker = registration.installing;