Example Usage
package main
import (
"io"
"log"
"net/http"
"github.com/jub0bs/cors"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("GET /hello", handleHello) // note: not configured for CORS
// create CORS middleware
cors, err := cors.NewMiddleware(cors.Config{
Origins: []string{"https://example.com"},
Methods: []string{http.MethodGet, http.MethodPost},
RequestHeaders: []string{"Authorization"},
})
if err != nil {
log.Fatal(err)
}
cors.SetDebug(true) // turn debug mode on (optional)
api := http.NewServeMux()
api.HandleFunc("GET /users", handleUsersGet)
api.HandleFunc("POST /users", handleUsersPost)
mux.Handle("/api/", http.StripPrefix("/api", cors.Wrap(api))) // note: method-less pattern here
if err := http.ListenAndServe(":8080", mux); err != http.ErrServerClosed {
log.Fatal(err)
}
}
func handleHello(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, "Hello, World!")
}
func handleUsersGet(_ http.ResponseWriter, _ *http.Request) {
// omitted
}
func handleUsersPost(_ http.ResponseWriter, _ *http.Request) {
// omitted
}
See also
xalgorix
Open Source
Xalgorix - The Most Powerful Open-Source AI Pentesting Agent…
graphql-cop
Open Source
Security Auditor Utility for GraphQL APIs…
API-Pentesting-Tools
Open Source
API Pentesting Tools are specialized security tools used to test and analyze the security of Applica…
GraphQL Voyager / InQL
Open Source
InQL is a Burp Suite and standalone GraphQL security scanner. Analyzes introspection queries, genera…
api-firewall
Open Source
Fast and light-weight API proxy firewall for request and response validation by OpenAPI specs.…
Interactsh
Open Source
Out-of-band interaction gathering server. Generates unique collaboration URLs for detecting blind vu…