v3/examples/server/README.md
Experimental - This feature is experimental and may change in future releases.
This example demonstrates running a Wails application in server mode - without a native GUI window.
Server mode allows you to run your Wails application as a pure HTTP server. This enables:
The recommended way to build server mode applications is using the Taskfile:
# Build for server mode
wails3 task build:server
# Build and run
wails3 task run:server
Or using Go directly:
# Build with server tag
go build -tags server -o myapp-server .
# Run
go run -tags server .
Then open http://localhost:8080 in your browser.
browser-1, browser-2, etc.Events work bidirectionally in server mode:
// Listen for events from browsers
app.Event.On("user-action", func(event *application.CustomEvent) {
log.Printf("Event from %s: %v", event.Sender, event.Data)
// event.Sender will be "browser-1", "browser-2", etc.
})
// Emit events to all browsers
app.Event.Emit("server-update", data)
Server mode is enabled by building with the server build tag. Configure the HTTP server options:
app := application.New(application.Options{
// Configure the HTTP server (used when built with -tags server)
Server: application.ServerOptions{
Host: "localhost", // Use "0.0.0.0" for all interfaces
Port: 8080,
},
// ... other options work the same as desktop mode
})
A health check endpoint is automatically available at /health:
curl http://localhost:8080/health
# {"status":"ok"}
# Using Taskfile (recommended)
wails3 task build:server
# Or using Go directly
go build -tags server -o myapp-server .
Build and run with Docker using the built-in tasks:
# Build Docker image
task build:docker
# Build and run
task run:docker
# Run on a different port
task run:docker PORT=3000
Or build manually:
docker build -t server-example .
docker run --rm -p 8080:8080 server-example
Since server mode runs without a native GUI, the following features are not available:
These APIs are safe to call but will have no effect or return default values.