CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
CI / Admin panel (push) Canceled after 0s
CI / Web client (push) Canceled after 0s
apps/desktop is the web client in a native window. It embeds the same build warp-web does and serves it through the same Go package, so every screen is shared. Unlike warp-web it proxies nothing: the client calls the homeserver directly, and the CSP allows the homeserver plus any https: and wss: origin for the call backend. - First run asks for the homeserver: a server name or address, with .well-known discovery and a /versions check; File > Change homeserver asks again. Signed-in sessions keep their own base URL, so a change never sends one server's token to another. - Links to other sites open in the system browser (/_desktop/links.js, added to index.html); only http, https and mailto are opened. - One instance at a time, since sessions and keys live in the webview's storage. - Dev builds open the DevTools Protocol on Windows when WARP_DESKTOP_REMOTE_DEBUGGING_PORT is set, for scripted testing. - Packaging: icon, version info and manifest in the Windows exe, a macOS .app with camera and microphone descriptions, Linux packages via nfpm. Make targets: desktop, desktop-run, desktop-test, desktop-resources, desktop-macos, desktop-linux. Web client: host and client move out of internal/ so the desktop app can import them, and host gains AnyCallOrigin. The Dockerfile, .dockerignore and the vite output path follow the move. Pinned to Wails v3.0.0-beta.27. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
142 lines
3.7 KiB
Go
142 lines
3.7 KiB
Go
// Command warp-web serves the Warp web client. It is optional: a Warp
|
|
// server runs without it, and anyone who wants the client in the browser
|
|
// runs this next to it.
|
|
//
|
|
// warp-web -homeserver http://localhost:8008 -listen :8080
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"flag"
|
|
"fmt"
|
|
"log/slog"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"os/signal"
|
|
"strings"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/dariuszjaniak/warp/apps/web/client"
|
|
"github.com/dariuszjaniak/warp/apps/web/host"
|
|
)
|
|
|
|
// Set with -ldflags "-X main.version=...".
|
|
var version = "0.0.0-dev"
|
|
|
|
func main() {
|
|
if err := run(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "warp-web:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func env(key, def string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return def
|
|
}
|
|
|
|
func parseURL(name, raw string) (*url.URL, error) {
|
|
u, err := url.Parse(strings.TrimRight(raw, "/"))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%s: %w", name, err)
|
|
}
|
|
return u, nil
|
|
}
|
|
|
|
func run() error {
|
|
listen := flag.String("listen", env("WARP_WEB_LISTEN", ":8080"), "address to listen on (WARP_WEB_LISTEN)")
|
|
homeserver := flag.String("homeserver", env("WARP_WEB_HOMESERVER", "http://localhost:8008"),
|
|
"base URL of the homeserver, proxied for the client (WARP_WEB_HOMESERVER)")
|
|
public := flag.String("public-homeserver", env("WARP_WEB_PUBLIC_HOMESERVER", ""),
|
|
"public URL of the homeserver; when set, the browser calls it directly and nothing is proxied (WARP_WEB_PUBLIC_HOMESERVER)")
|
|
callOrigins := flag.String("call-origins", env("WARP_WEB_CALL_ORIGINS", ""),
|
|
"space-separated origins of the LiveKit JWT service and SFU the browser may connect to for group calls (WARP_WEB_CALL_ORIGINS)")
|
|
logFormat := flag.String("log-format", env("WARP_WEB_LOG_FORMAT", "text"), "text or json (WARP_WEB_LOG_FORMAT)")
|
|
showVersion := flag.Bool("version", false, "print the version and exit")
|
|
flag.Parse()
|
|
|
|
if *showVersion {
|
|
fmt.Println("warp-web", version)
|
|
return nil
|
|
}
|
|
|
|
var logger *slog.Logger
|
|
switch *logFormat {
|
|
case "json":
|
|
logger = slog.New(slog.NewJSONHandler(os.Stderr, nil))
|
|
case "text":
|
|
logger = slog.New(slog.NewTextHandler(os.Stderr, nil))
|
|
default:
|
|
return fmt.Errorf("unknown log format %q", *logFormat)
|
|
}
|
|
slog.SetDefault(logger)
|
|
|
|
opts := host.Options{Logger: logger, Version: version, CallOrigins: strings.Fields(*callOrigins)}
|
|
mode, target := "proxy", *homeserver
|
|
if *public != "" {
|
|
u, err := parseURL("public-homeserver", *public)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opts.PublicHomeserver = u
|
|
mode, target = "direct", *public
|
|
} else {
|
|
u, err := parseURL("homeserver", *homeserver)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opts.Homeserver = u
|
|
}
|
|
|
|
files, built := client.FS()
|
|
if !built {
|
|
logger.Warn("the web client was not built into this binary; serving a placeholder page")
|
|
files = nil
|
|
}
|
|
opts.Client = files
|
|
|
|
h, err := host.New(opts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
srv := &http.Server{
|
|
Addr: *listen,
|
|
Handler: h,
|
|
ReadHeaderTimeout: 10 * time.Second,
|
|
// Uploads and downloads of large media pass through here.
|
|
ReadTimeout: 15 * time.Minute,
|
|
WriteTimeout: 15 * time.Minute,
|
|
IdleTimeout: 2 * time.Minute,
|
|
MaxHeaderBytes: 64 << 10,
|
|
}
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
errc := make(chan error, 1)
|
|
go func() {
|
|
logger.Info("warp-web listening", "addr", *listen, "homeserver", target, "mode", mode, "version", version)
|
|
errc <- srv.ListenAndServe()
|
|
}()
|
|
|
|
select {
|
|
case err := <-errc:
|
|
if !errors.Is(err, http.ErrServerClosed) {
|
|
return err
|
|
}
|
|
return nil
|
|
case <-ctx.Done():
|
|
}
|
|
|
|
logger.Info("shutting down")
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
defer cancel()
|
|
return srv.Shutdown(shutdownCtx)
|
|
}
|