spaproxy

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MIT Imports: 15 Imported by: 4

README

go-spaproxy

Generic GoLang middleware to reverse proxy SPA development files to allow hot reload functionality while developing.

Build Status codecov

Supported JavaScript frameworks

Any framework can be supported as long as it has development web server to start but additional helpers are available for following frameworks:

Usage

To use proxy instance needs to be created and then started using SpaDevProxy.Start() method.

Later You can use SpaDevProxy.HandleFunc(w http.ResponseWriter, r *http.Request) method to add it to applications catch all route that would proxy all not application requests to background development server.

NB! Application need to gracefully shutdown and call SpaDevProxy.Stop() method otherwise started node background server will not be stopped.

For examples on how to integrate see examples folder:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFreePort

func GetFreePort(port int) (int, error)

GetFreePort checks and returns free port if specified port is privildeged port or zero

Types

type AngularDevProxyOptions

type AngularDevProxyOptions struct {
	RunnerType RunnerType
	ScriptName string
	Dir        string
	Port       int
	Production bool
}

AngularDevProxyOptions represents Angular development proxy options.

type ReactDevProxyOptions

type ReactDevProxyOptions struct {
	RunnerType    RunnerType
	ShowBuildInfo bool
	ScriptName    string
	Dir           string
	Port          int
}

ReactDevProxyOptions represents React development proxy options.

type RunnerType

type RunnerType int

RunnerType runner type.

const (
	// RunnerTypeNpm runner type NPM.
	RunnerTypeNpm RunnerType = iota

	// RunnerTypeNpx runner type NPX.
	RunnerTypeNpx

	//RunnerTypeYarn runner type Yarn.
	RunnerTypeYarn

	// RunnerTypeCustom custom runner type.
	RunnerTypeCustom
)

type SpaDevProxy

type SpaDevProxy interface {
	// Start backgroud process and wait when it is ready to accept connections.
	Start(ctx context.Context) error

	// Stop background process by killing it.
	Stop() error

	// DevServerURL returns development server URL.
	DevServerURL() *url.URL

	// HandleFunc handles reverse proxy function.
	HandleFunc(w http.ResponseWriter, r *http.Request)
}

SpaDevProxy instance.

func NewAngularDevProxy

func NewAngularDevProxy(options *AngularDevProxyOptions) (SpaDevProxy, error)

NewAngularDevProxy returns new SpaDevProxy instance for Angular development.

func NewReactDevProxy

func NewReactDevProxy(options *ReactDevProxyOptions) (SpaDevProxy, error)

NewReactDevProxy returns new SpaDevProxy instance for React development.

func NewSpaDevProxy

func NewSpaDevProxy(options *SpaDevProxyOptions) (SpaDevProxy, error)

NewSpaDevProxy creates new SpaDevProxy instance.

func NewSvelteDevProxy

func NewSvelteDevProxy(options *SvelteDevProxyOptions) (SpaDevProxy, error)

NewSvelteDevProxy returns new SpaDevProxy instance for SvelteJS development.

func NewVueDevProxy

func NewVueDevProxy(options *VueDevProxyOptions) (SpaDevProxy, error)

NewVueDevProxy returns new SpaDevProxy instance for VueJS development.

type SpaDevProxyOptions

type SpaDevProxyOptions struct {
	// RunnerType to use. Defaults to NPM.
	RunnerType RunnerType

	// ScriptName is the name of the script to run.
	ScriptName string

	// Args holds command line arguments.
	Args []string

	// Env specifies the environment of the process.
	// Each entry is of the form "key=value".
	// If Env is nil, the new process uses the current process's
	// environment.
	// If Env contains duplicate environment keys, only the last
	// value in the slice for each duplicate key is used.
	// As a special case on Windows, SYSTEMROOT is always added if
	// missing and not explicitly set to the empty string.
	Env []string

	// Dir specifies the working directory of the command.
	// If Dir is the empty string, Start runs the command in the
	// calling process's current directory.
	Dir string

	// StartRegexp specifies regular expression used to detect
	// when background process is ready to accept incomming requests.
	StartRegexp *regexp.Regexp

	// Port specifies localhost port that background service is
	// using to accept requests.
	Port int

	// ShowBuildInfo specifies option either to show webpack building
	// progress or not.
	ShowBuildInfo bool
}

SpaDevProxyOptions options to use for SpaDevProxy.

type SvelteDevProxyOptions

type SvelteDevProxyOptions struct {
	RunnerType RunnerType
	ScriptName string
	Dir        string
	Port       int
}

SvelteDevProxyOptions represents Svelte development proxy options.

type VueDevProxyOptions

type VueDevProxyOptions struct {
	RunnerType RunnerType
	ScriptName string
	Dir        string
	Port       int
	Mode       string
}

VueDevProxyOptions represents VueJS development proxy options.

Directories

Path Synopsis
examples
echo Module
gin Module
go-chi Module
simple Module

Jump to

Keyboard shortcuts

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