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
GraphQL Voyager / InQL
Open Source
InQL is a Burp Suite and standalone GraphQL security scanner. Analyzes introspection queries, genera…
NoSQLMap
Open Source
Automated NoSQL injection and database exploitation tool. Targets MongoDB, CouchDB, Redis, and Cassa…
devguard
Free
DevGuard Backend - Secure your Software Supply Chain - Attestation-based compliance as Code, manage …
OWASP ZAP
Open Source
Kali
OWASP's Zed Attack Proxy — one of the world's most popular free web application security scanners. F…
waf-bypass
Open Source
Check your WAF before an attacker does…
Interactsh
Open Source
Out-of-band interaction gathering server. Generates unique collaboration URLs for detecting blind vu…