cors

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 4 Imported by: 55

README

CORS

Release Discord Test Security Linter

Install
go get -u github.com/gofiber/fiber
go get -u github.com/gofiber/cors
config
Property Type Description Default
Filter func(*Ctx) bool Defines a function to skip middleware nil
AllowOrigins []string AllowOrigin defines a list of origins that may access the resource. []string{"*"}
AllowMethods []string AllowMethods defines a list methods allowed when accessing the resource. This is used in response to a preflight request. []string{"GET", "POST", "HEAD", "PUT", "DELETE", "PATCH"}
AllowCredentials bool AllowCredentials indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials. false
ExposeHeaders []string ExposeHeaders defines a whitelist headers that clients are allowed to access. []string{}
MaxAge int MaxAge indicates how long (in seconds) the results of a preflight request can be cached. 0
Example
package main

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/cors"
)

func main() {
  app := fiber.New()

  app.Use(cors.New())

  app.Get("/", func(c *fiber.Ctx) {
    c.Send("Welcome!")
  }) 

  app.Listen(3000)
}
Test
curl -H "Origin: http://example.com" --verbose http://localhost:3000

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config ...Config) func(*fiber.Ctx)

New ...

Types

type Config

type Config struct {
	// Filter defines a function to skip middleware.
	// Optional. Default: nil
	Filter func(*fiber.Ctx) bool
	// Optional. Default value []string{"*"}.
	AllowOrigins []string
	// Optional. Default value []string{"GET","POST","HEAD","PUT","DELETE","PATCH"}
	AllowMethods []string
	// Optional. Default value []string{}.
	AllowHeaders []string
	// Optional. Default value false.
	AllowCredentials bool
	// Optional. Default value []string{}.
	ExposeHeaders []string
	// Optional. Default value 0.
	MaxAge int
}

Config ...

Jump to

Keyboard shortcuts

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