devenv-shopware icon indicating copy to clipboard operation
devenv-shopware copied to clipboard

Watch-Scripts: Hot proxy doesn't work with https?

Open Songworks opened this issue 2 years ago • 0 comments

The webpack hot proxy used by the bin/watch-xyz.sh scripts doesn't seem to work at all with or over https. Or at least I couldn't get it to work over https.

There are parts of it that seem to be hardcoded to always run over http (asset-urls, I think it was) and in the end it always failed with Client sent an HTTP request to an HTTPS server., one way or another.

I guess the Shopware developers never expected anyone to run a local environment using only https. :)

Anyway, I am writing this down in the hope that you might know a solution? Or, if you are interested, implement one so that we can run the watchers by default in your devenv environment too?

And if it helps anyone: So far my "solution" has been to add another caddy virtualHost with the exact same extraConfig but running over http. Plus some script aliases to use it for the watchers:

devenv.local.nix:

{ pkgs, config, inputs, lib, ... }:

{
  # HTTP Host for webpack hot-proxy to work
  services.caddy.virtualHosts."http://127.0.0.1:8001" = {
    # Same as https virtualHosts
    extraConfig = ''
      @default {
        not path /theme/* /media/* /thumbnail/* /bundles/* /css/* /fonts/* /js/* /recovery/* /sitemap/*
        not expression header_regexp('xdebug', 'Cookie', 'XDEBUG_SESSION') || query({'XDEBUG_SESSION': '*'})
      }
      @debugger {
        not path /theme/* /media/* /thumbnail/* /bundles/* /css/* /fonts/* /js/* /recovery/* /sitemap/*
        expression header_regexp('xdebug', 'Cookie', 'XDEBUG_SESSION') || query({'XDEBUG_SESSION': '*'})
      }

      tls internal
      root * public
      php_fastcgi @default unix/${config.languages.php.fpm.pools.web.socket}
      php_fastcgi @debugger unix/${config.languages.php.fpm.pools.xdebug.socket}
      encode zstd gzip
      file_server
      log {
        output stderr
        format console
        level ERROR
      }
    '';
  };

  # Aliases, it's necessary to set APP_URL for the watchers, otherwise the
  # hot-proxy throws `Client sent an HTTP request to an HTTPS server.`
  scripts.bstf.exec = "bin/build-storefront.sh";
  scripts.badm.exec = "bin/build-administration.sh";
  scripts.wstf.exec = "export APP_URL=http://127.0.0.1:8001 && bin/watch-storefront.sh";
  scripts.wadm.exec = "export APP_URL=http://127.0.0.1:8001 && bin/watch-administration.sh";
}

Cheers!

Songworks avatar Feb 09 '23 10:02 Songworks