Introduction

In the current environment, I have to do some side jobs to make a living, mainly helping others set up private services. I often encounter people who want to preview whether a service’s functionality meets their requirements. Initially, I used Tailscale, allowing them to connect to my internal environment, which required them to download Tailscale and register through a series of operations!

Not only that, because I use self-signed certificates locally, the other party also needs to add trusted CAs and modify host resolution configurations.

This sounds very troublesome… so I’ve been looking for a simple solution, and finally discovered the Expose tool!

Overview

Expose is developed by the BeyoundCode team based on PHP, with a built-in clean and beautiful management UI, as well as a simple and easy-to-use CLI.

Console

Server

The docker-compose.yaml configuration file for Expose Server:

services:
  expose:
    image: beyondcodegmbh/expose-server:latest
    labels:
      - traefik.enable=true
      - traefik.http.routers.expose.tls=true
      - traefik.http.routers.expose.tls.certResolver=betterde
      - traefik.http.routers.expose.rule=Host(`example.com`)
      - traefik.http.routers.expose.service=expose
      - traefik.http.routers.expose.entrypoints=http,https
      - traefik.http.services.expose.loadbalancer.server.port=443

      - traefik.http.routers.tunnel.tls=true
      - traefik.http.routers.tunnel.tls.certResolver=example
      - traefik.http.routers.tunnel.tls.domains[0].main=example.com
      - traefik.http.routers.tunnel.tls.domains[0].sans=*.example.com
      - traefik.http.routers.tunnel.rule=HostRegexp(`^.+.example.com$`)
      - traefik.http.routers.tunnel.service=tunnel
      - traefik.http.routers.tunnel.priority=5
      - traefik.http.routers.tunnel.entrypoints=http,https
      - traefik.http.services.tunnel.loadbalancer.server.port=443
    restart: no
    volumes:
      - ./config/expose.php:/src/config/expose.php
      - ./database/expose.db:/root/.expose
    hostname: expose
    networks:
      - traefik
    extra_hosts:
      - host.docker.internal:host-gateway
    environment:
      port: 443
      domain: example.com
      username: ${USERNAME}
      password: ${PASSWORD}
    container_name: expose

networks:
  traefik:
    external: true

The subdomain for Expose’s admin backend must be expose. If you cannot use this subdomain, you need to modify its default configuration file. In the container’s /src/config/expose.php file, find admin.subdomain and change it to your own subdomain. For example, here it’s tunnel.example.com.

Client

Install the CLI:

composer global require beyondcode/expose

Then modify the following configurations in the ~/.expose/config.php file according to your actual situation:

  • servers.main.host: The Domain of Expose Server;
  • servers.main.port: The Port of Expose Server;
  • server_endpoint: The URL of Expose API;
  • default_server: The default server, which is the key in the servers array, i.e., main;
  • default_domain: The access domain TLD after the Tunnel is started;
  • auth_token: The Token created for the user in the admin backend.

After configuration, you can share your local services!

Sharing

# Start the local service
miniserve --index index.html --port 4000
miniserve v0.27.1
Bound to [::]:4000, 0.0.0.0:4000
Serving path /Users/George/Develop/betterde/website
Available at (non-exhaustive list):
    http://10.0.6.8:4000
    http://10.8.10.0:4000
    http://127.0.0.1:4000
    http://198.19.249.3:4000
    http://[::1]:4000
    http://[240e:b65:d60:83bb:871:86ee:8e39:2a65]:4000
    http://[240e:b65:d60:83bb:14b2:8244:b01f:aa47]:4000
    http://[240e:b65:d60:83bb:4cac:d479:9839:f5ac]:4000
    http://[240e:b65:d60:83bb:a837:4ab:1706:e731]:4000
    http://[240e:b65:d60:83bb:bed0:74ff:fe20:1efe]:4000
    http://[fd07:b51a:cc66:0:a617:db5e:ab7:e9f1]:4000

Quit by pressing CTRL-C

# Start the expose tunnel
expose share --subdomain www -- http://127.0.0.1:4000

Thank you for using expose.
Shared URL:		127.0.0.1:4000
Dashboard:		http://127.0.0.1:4040
Public HTTP:	http://www.example.com
Public HTTPS:	https://www.example.com

Now you can share the external connection with visitors. If you need paid assistance with deployment, you can contact WeChat: GeorgeBornAgain, please specify your purpose, thank you!

Conclusion

Expose not only provides good support for Laravel’s Valet but also supports most services, even TCP port connection forwarding. Once deployed, you no longer have to worry about deploying service demos!

I hope this is helpful, Happy hacking…