unisrv (Unity Server for WebGL)
unisrv
is a preview server for Unity WebGL applications.
Notice: This project is focused on local preview only. Not recommended for production use.
Usage
CLI
Installation
Download the binary from the releases.
Running
To start the server, execute the following in your WebGL build location:
unisrv
Or specify the build location expressly:
unisrv ./Build/
Configurations
The server is configurable via the following options or environment variables.
Option | Environment Variable | Default Value | Description |
---|
-base | UNISRV_BASE | | The base path for Unity application. |
-disable-no-cache | UNISRV_DISABLE_NO_CACHE | false | Disable setting Cache-Control: no-cache header. |
-host | UNISRV_HOST | localhost | The hostname to listen on. |
-port | UNISRV_PORT | 5000 | The port number to listen on. |
-read-timeout | UNISRV_READ_TIMEOUT | 5 | The maximum duration for reading request. |
-write-timeout | UNISRV_WRITE_TIMEOUT | 5 | The maximum duration for writing response. |
Docker image
Docker images are also available.
docker run --rm -v $(pwd):/app -p 5000:5000 frozenbonito/unisrv
Mount your Unity application to /app
directory in the container.
Library
It can also be used as a library for Go.
For example:
package main
import (
"net/http"
"github.com/frozenbonito/unisrv"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
func main() {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Mount("/", unisrv.NewHandler("/path/to/unity-build-location", nil))
http.ListenAndServe(":8080", r)
}
See go.dev for more details.
Related project
Unity Preview Server - Unity editor extension powered by unisrv.