spa_server

package module
v0.0.0-...-bb87b4f Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2017 License: MIT Imports: 3 Imported by: 2

README

spa-server

Go SPA (single page application) server handler

Get the package:

$ go get github.com/roberthodgen/spa-server

Use the package:

import "github.com/roberthodgen/spa-server"

For simple single page application serving using Go's http package.

API

func SpaHandler(publicDir string, indexFile string) http.Handler

Returns a request handler (http.Handler) that serves a single page application from a given directory (publicDir).

It falls back to a supplied index (indexFile) when either condition is true:

  1. Request (file) path is not found
  2. Request path is a directory

Examples

Serve only a single page application:

package main
import "net/http"
import spa "github.com/roberthodgen/spa-server"

func main() {
    http.ListenAndServe(":8080", spa.SpaHandler("public", "index.html"))
}

Serve a single page application along side other paths:

package main
import "net/http"
import spa "github.com/roberthodgen/spa-server"

func main() {
    http.Handle("/app", spa.SpaHandler("webapp", "app.html"))
    // other handlers
    http.ListenAndServe(":8080", nil)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SpaHandler

func SpaHandler(publicDir string, indexFile string) http.Handler

Returns a request handler (http.Handler) that serves a single page application from a given public directory (publicDir).

Types

This section is empty.

Jump to

Keyboard shortcuts

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