unisrv

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 3 Imported by: 0

README

unisrv (Unity Server for WebGL)

Go Reference CI License Release

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.

Documentation

Overview

Package unisrv implements http helpers for serving Unity WebGL application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(dir string, opts *Options) http.Handler

NewHandler returns a handler that serves Unity application.

func UnityMiddleware

func UnityMiddleware(next http.Handler) http.Handler

UnityMiddleware is a middleware for serving Unity application.

Types

type Options

type Options struct {
	// Base specifies the base path for the Unity application.
	Base string
	// NoCache specifies whether to set `Cache-Control: no-cache` header.
	NoCache bool
}

Options describes options for unisrv handler.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL