Can't fully access website from LAN with WSL2

Hi,

I’m using Sage 10 (6.15.2) in WSL2 with Ubuntu 22.04.2 LTS in Windows 10 Pro 22H2.

I cannot seem to make the dev server work properly from another device connected to my LAN. It works perfectly from Windows (at https://localhost:3000/). I tried port forwarding methods or using expose-wsl with my firewall disabled but all I can reach is the unstyled content of my home page.

From my phone, with either of these setups, if I access https://192.168.1.17:3000, the page doesn’t load the images nor the stylesheets, and if I click on any link it tries to load the url https://localhost:3000/page rather than https://192.168.1.17:3000/page. I assume it has to do with my bud or apache config but I can’t seem to solve the issue.

Here are the paths in my bud.config.js

 /**
   * Set public path
   */
  app.setPublicPath('/wp-content/themes/mydomain/public/');

  /**
   * Development server settings
   */
  app
    .setUrl({
      url: new URL('https://localhost:3000'),
      cert: '/etc/ssl/certs/apache-selfsigned.crt',
      key: '/etc/ssl/private/apache-selfsigned.key',
      }
    )
    .setProxyUrl('https://dev.mydomain.fr/')
    .watch(['resources/views', 'app']);

And mydomain.fr.conf

<VirtualHost *:443>
  ServerAdmin webadmin@mydomain.fr
  ServerName  dev.mydomain.fr
  ServerAlias www.dev.mydomain.fr

  DirectoryIndex index.html index.php
  DocumentRoot /home/name/public_html/mydomain.fr/public

  <Directory /home/name/public_html/mydomain.fr/public>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

  SSLEngine on
   SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
   SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

  LogLevel warn
  ErrorLog /var/log/apache2/error-mydomain.fr.log
  CustomLog /var/log/apache2/access-mydomain.fr.log combined

</VirtualHost>

<VirtualHost *:80>
    ServerName dev.mydomain.fr
    Redirect / https://dev.mydomain.fr/
</VirtualHost>

I have read pretty much anything I could find about this issue, and I’m no running out of ideas, anyone has an idea of how I could make it work ?

Thanks

Hi @Pierrealex,

Sounds really frustrating. I think you’re close though.

If you specify app.setPublicUrl('https://192.168.1.17:3000') does that fix the styles?

.setPublicUrl() sets the string that the HMR proxy uses to rewrite URLs. By default, it’s trying to keep you ‘inside’ the HMR server, hence rewriting your .setProxyUrl() to https://localhost:3000. As you’re accessing from the LAN, this needs to be updated to point to your LAN accessible address.

Exposing WSL to the LAN is the right move here (and your Apache config looks like it’ll respond on the LAN), but I think you just need this last step. I could be wrong…

Tom

2 Likes

Hi Tom,

That did it thank you so much ! I now have to use https://192.168.1.17:3000’ instead of localhost from Windows too but that’s not an issue.

I hope this helps other people too because information is quite scarce on this specific subject !

Thanks again,

Pierre

2 Likes