cors

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cors lets other origins call a Tern app's endpoints:

ternApp(kit.WithPlugins(cors.New(
	cors.Origins("https://app.example.com"),
	cors.Paths("/api/"),
)))

It answers preflight requests, adds the CORS headers to responses, and trusts the listed origins for Tern's cross-site request protection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Plugin)

Option configures the plugin.

func Credentials

func Credentials() Option

Credentials allows cookies and HTTP authentication on cross-origin requests.

func Headers

func Headers(h ...string) Option

Headers sets the request headers clients may send. The default is Content-Type and Authorization.

func MaxAge

func MaxAge(d time.Duration) Option

MaxAge sets how long browsers may cache a preflight. The default is 10 minutes.

func Methods

func Methods(m ...string) Option

Methods sets the allowed methods. The default is GET, HEAD, POST, PUT, PATCH and DELETE.

func Origins

func Origins(origins ...string) Option

Origins lists the origins allowed to make requests, such as "https://app.example.com". "*" allows any origin, but not with credentials.

func Paths

func Paths(prefixes ...string) Option

Paths limits CORS to URL paths starting with one of the prefixes, such as "/api/". The default is every path.

type Plugin

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

Plugin handles CORS. Create it with New.

func New

func New(opts ...Option) *Plugin

New returns the CORS plugin.

func (*Plugin) Name

func (*Plugin) Name() string

Name implements kit.Plugin.

func (*Plugin) Setup

func (p *Plugin) Setup(s *kit.Setup) error

Setup implements kit.Plugin.

Jump to

Keyboard shortcuts

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