adapters

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2017 License: MIT Imports: 13 Imported by: 0

README

package adapters

This package contains implementations of the Adapter interface that control different backend applications.

The interface is currently defined as

type Adapter interface {
	Command() *exec.Cmd
	Start() error
	Stop() error
	WriteLog(io.Writer)
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

The ServeHTTP function means all adapters implement the http.Handler interface.

Working implementations

Simple Proxy

A proxy is configured by creating a file in the ~/.phx-dev folder containing the host/port combination that you want to proxy to. You can specify just a port and it will assume localhost.

echo "http://127.0.0.1:3000" > ~/.phx-dev/mysite.dev echo "4000" > ~/.phx-dev/othersite.dev

Elixir/Phoenix

When a mix.exs file is detected in the root of the dir that a symlink points to and contains the phoenix package then a mix phx.server server will be launched on a random port and requests will be proxied to that application.

To configure a phoenix application simply create a symbolic link to the phoenix application and update your config/dev.exs file to allow phx-dev to override the default 4000 http port.

ln -sf /path/to/phoenix/app ~/.phx-dev/mysite.dev

config/mix.exs

config :your_app, YourApp.Web.Endpoint,
  http: [port: System.get_env("PHX_PORT") || 4000],
Static HTML

To enable a static HTML site, simply symlink to a the public directory where the static files live. Files in the directory will be served, if a directory root is requested index.html files will be served if they exist.

ln -sf /path/to/static/public ~/.phx-dev/mysite.dev

TODO

  • Ruby/Rails
  • Ruby/Hanami
  • Ruby/Rack
  • Ruby/Rakefile
  • Docker (Compose)
  • Procfile
  • Go/Buffalo
  • Node/package.json
  • PHP

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	Command() *exec.Cmd
	Start() error
	Stop() error
	WriteLog(io.Writer)
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Adapter defines the interface for an Adapter implementation

func CreatePhoenixAdapter

func CreatePhoenixAdapter(host, dir string) (Adapter, error)

CreatePhoenixAdapter creates a new phoenix adapter

func CreateProxyAdapter

func CreateProxyAdapter(host, port string) (Adapter, error)

CreateProxyAdapter creates a new proxy

func CreateRailsAdapter

func CreateRailsAdapter(host, dir string) (Adapter, error)

CreateRailsAdapter creates a new rails adapter

func CreateStaticAdapter

func CreateStaticAdapter(dir string) (Adapter, error)

CreateStaticAdapter creates a new static HTML application

type PhoenixAdapter

type PhoenixAdapter struct {
	Host string
	Dir  string
	Port string
	// contains filtered or unexported fields
}

PhoenixAdapter holds the state for the application

func (*PhoenixAdapter) Command

func (d *PhoenixAdapter) Command() *exec.Cmd

Command returns the command used to start the application

func (*PhoenixAdapter) ServeHTTP

func (d *PhoenixAdapter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

func (*PhoenixAdapter) Start

func (d *PhoenixAdapter) Start() error

Start starts a phoenix application

func (*PhoenixAdapter) Stop

func (d *PhoenixAdapter) Stop() error

Stop stops a phoenix application

func (*PhoenixAdapter) WriteLog

func (d *PhoenixAdapter) WriteLog(w io.Writer)

WriteLog writes out the application log to the given writer

type ProxyAdapter

type ProxyAdapter struct {
	Host string
	Port string
	// contains filtered or unexported fields
}

ProxyAdapter holds the state for the application

func (*ProxyAdapter) Command

func (d *ProxyAdapter) Command() *exec.Cmd

Command doesn't do anything

func (*ProxyAdapter) ServeHTTP

func (d *ProxyAdapter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

func (*ProxyAdapter) Start

func (d *ProxyAdapter) Start() error

Start starts the proxy

func (*ProxyAdapter) Stop

func (d *ProxyAdapter) Stop() error

Stop doesn't do anything

func (*ProxyAdapter) WriteLog

func (d *ProxyAdapter) WriteLog(w io.Writer)

WriteLog doesn't do anything

type RailsAdapter

type RailsAdapter struct {
	Host string
	Dir  string
	Port string
	// contains filtered or unexported fields
}

RailsAdapter holds the state for the application

func (*RailsAdapter) Command

func (a *RailsAdapter) Command() *exec.Cmd

Command returns the command used to stat the application

func (*RailsAdapter) ServeHTTP

func (a *RailsAdapter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

func (*RailsAdapter) Start

func (a *RailsAdapter) Start() error

Start starts the application

func (*RailsAdapter) Stop

func (a *RailsAdapter) Stop() error

Stop stops the application

func (*RailsAdapter) WriteLog

func (a *RailsAdapter) WriteLog(w io.Writer)

WriteLog doesn't do anything

type StaticAdapter

type StaticAdapter struct {
	Dir string
}

StaticAdapter holds the state for the application

func (*StaticAdapter) Command

func (d *StaticAdapter) Command() *exec.Cmd

Command doesn't do anything

func (*StaticAdapter) ServeHTTP

func (d *StaticAdapter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

func (*StaticAdapter) Start

func (d *StaticAdapter) Start() error

Start doesn't do anything

func (*StaticAdapter) Stop

func (d *StaticAdapter) Stop() error

Stop doesn't do anything

func (*StaticAdapter) WriteLog

func (d *StaticAdapter) WriteLog(w io.Writer)

WriteLog doesn't do anything

Jump to

Keyboard shortcuts

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