server

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 29 Imported by: 2

README

Server

The server package is responsible for handling webserver requests for map tiles and various JSON endpoints describing the configured server. Example config:

[webserver]
port = ":9090"              # set something different than default ":8080"
ssl_cert = "fullchain.pem"  # ssl cert for serving by https
ssl_key = "privkey.pem"     # ssl key for serving by https


[webserver.headers]
Access-Control-Allow-Origin = "*"
Config properties
  • port (string): [Optional] Port and bind string. For example ":9090" or "127.0.0.1:9090". Defaults to ":8080"
  • hostname (string): [Optional] The hostname to use in the various JSON endpoints. This is useful if tegola is behind a proxy and can't read the API consumer's request host directly.
  • uri_prefix (string): [Optional] A prefix to add to all API routes. This is useful when tegola is behind a proxy (i.e. example.com/tegola). The prexfix will be added to all URLs included in the capabilities endpoint responses.
  • ssl_cert (string): [Optional, unless ssl_key provided] Path to a certificate file for serving through HTTPS
  • ssl_key (string): [Optional, unless ssl_cert provided] Path to a private key file for serving through HTTPS

Local development of the embedded viewer

Tegola's built in viewer code is stored in the ui/ directory. To build the ui npm must be installed. Once npm is installed the following command can be run from the repository root to generate a .go file for inclusion in the tegola binary:

go generate ./server

Disabling the viewer

The viewer can be excluded during building by using the build flag noViewer. For example, building tegola from the cmd/tegola directory:

go build -tags "noViewer"

Documentation

Overview

Package server implements the http frontend

Index

Constants

View Source
const (
	// MaxTileSize is 500k. Currently, just throws a warning when tile
	// is larger than MaxTileSize
	MaxTileSize = 500000
)

Variables

View Source
var (
	// Version is the version of the software, this should be set by the main program, before starting up.
	// It is used by various Middleware to determine the version.
	Version string = "version not set"

	// HostName is the name of the host to use for construction of URLS.
	// configurable via the tegola config.toml file (set in main.go)
	HostName string

	// Port is the port the server is listening on, used for construction of URLS.
	// configurable via the tegola config.toml file (set in main.go)
	Port string

	// SSLCert is a filepath to an SSL cert, this will be used to enable https
	SSLCert string

	// SSLKey is a filepath to an SSL key, this will be used to enable https
	SSLKey string

	// Headers is the map of user defined response headers.
	// configurable via the tegola config.toml file (set in main.go)
	Headers = map[string]string{}

	// URIPrefix sets a prefix on all server endpoints. This is often used
	// when the server sits behind a reverse proxy with a prefix (i.e. /tegola)
	URIPrefix = "/"

	// ProxyProtocol is a custom protocol that will be used to generate the URLs
	// included in the capabilities endpoint responses. This is useful when he
	// server sits behind a reverse proxy
	// (See https://github.com/go-spatial/tegola/pull/967)
	ProxyProtocol string

	// DefaultCORSHeaders define the default CORS response headers added to all requests
	DefaultCORSHeaders = map[string]string{
		"Access-Control-Allow-Origin":  "*",
		"Access-Control-Allow-Methods": "GET, OPTIONS",
	}
)
View Source
var URLRoot = func(r *http.Request) *url.URL {
	root := url.URL{
		Scheme: scheme(r),
		Host:   hostName(r),
	}

	return &root
}

URLRoot builds a string containing the scheme, host and port based on a combination of user defined values, headers and request parameters. The function is public so it can be overridden for other implementations.

Functions

func GZipHandler added in v0.8.0

func GZipHandler(next http.Handler) http.Handler

GZipHandler is responsible for determining if the incoming request should be served gzipped data. All response data is assumed to be compressed prior to being passed to this handler.

If the incoming request has the "Accept-Encoding" header set with the values of "gzip" or "*" the response header "Content-Encoding: gzip" is set and the compressed data is returned.

If no "Accept-Encoding" header is present or "Accept-Encoding" has a value of "gzip;q=0" or "*;q=0" the response is decompressed prior to being sent to the client.

func HeadersHandler added in v0.8.0

func HeadersHandler(next http.Handler) http.Handler

HeadersHandler is middleware for adding user defined response headers

func NewRouter added in v0.7.0

func NewRouter(a *atlas.Atlas) *httptreemux.TreeMux

NewRouter set's up our routes.

func Start

func Start(a *atlas.Atlas, port string) *http.Server

Start starts the tile server binding to the provided port

func TileCacheHandler added in v0.4.0

func TileCacheHandler(a *atlas.Atlas, next http.Handler) http.Handler

TileCacheHandler implements a request cache for tiles on requests when the URLs have a /:z/:x/:y scheme suffix (i.e. /osm/1/3/4.pbf)

Types

type Capabilities added in v0.3.0

type Capabilities struct {
	Version string            `json:"version"`
	Maps    []CapabilitiesMap `json:"maps"`
}

type CapabilitiesLayer added in v0.3.0

type CapabilitiesLayer struct {
	Name    string   `json:"name"`
	Tiles   []string `json:"tiles"`
	MinZoom uint     `json:"minzoom"`
	MaxZoom uint     `json:"maxzoom"`
}

type CapabilitiesMap added in v0.3.0

type CapabilitiesMap struct {
	Name         string              `json:"name"`
	Attribution  string              `json:"attribution"`
	Bounds       *geom.Extent        `json:"bounds"`
	Center       [3]float64          `json:"center"`
	Tiles        []string            `json:"tiles"`
	Capabilities string              `json:"capabilities"`
	Layers       []CapabilitiesLayer `json:"layers"`
}

type HandleCapabilities added in v0.3.0

type HandleCapabilities struct{}

func (HandleCapabilities) ServeHTTP added in v0.3.0

func (req HandleCapabilities) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandleMapCapabilities added in v0.3.1

type HandleMapCapabilities struct {
	// contains filtered or unexported fields
}

func (HandleMapCapabilities) ServeHTTP added in v0.3.1

func (req HandleMapCapabilities) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP returns details about a map according to the tileJSON spec (https://github.com/mapbox/tilejson-spec/tree/master/2.1.0)

URI scheme: /capabilities/:map_name.json map_name - map name in the config file

type HandleMapLayerZXY added in v0.3.1

type HandleMapLayerZXY struct {

	// the Atlas to use, nil (default) is the default atlas
	Atlas *atlas.Atlas
	// contains filtered or unexported fields
}

func (HandleMapLayerZXY) ServeHTTP added in v0.3.1

func (req HandleMapLayerZXY) ServeHTTP(w http.ResponseWriter, r *http.Request)

URI scheme: /maps/:map_name/:layer_name/:z/:x/:y?param=value map_name - map name in the config file layer_name - name of the single map layer to render z, x, y - tile coordinates as described in the Slippy Map Tilenames specification

z - zoom level
x - row
y - column

param - configurable query parameters and their values

type HandleMapStyle added in v0.4.0

type HandleMapStyle struct {
	// contains filtered or unexported fields
}

func (HandleMapStyle) ServeHTTP added in v0.4.0

func (req HandleMapStyle) ServeHTTP(w http.ResponseWriter, r *http.Request)

returns details about a map according to the tileJSON spec (https://github.com/mapbox/tilejson-spec/tree/master/2.1.0)

URI scheme: /capabilities/:map_name.json

map_name - map name in the config file

Jump to

Keyboard shortcuts

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