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
xurlfind3r
Open Source
A command-line utility designed to discover URLs for a given domain in a simple, efficient way. It w…
Burp Suite Extensions (BApp Store)
Freemium
Marketplace of extensions for Burp Suite covering active/passive scanning, custom insertion points, …
EyeWitness
Open Source
Kali
Takes screenshots of web pages, RDP, and VNC services. Reports on default credentials and interestin…
OWASP ZAP
Open Source
Kali
OWASP's Zed Attack Proxy — one of the world's most popular free web application security scanners. F…
Penetration_Testing_POC
Open Source
渗透测试有关的POC、EXP、脚本、提权、小工具等---About penetration-testing python-script poc getshell csrf xss cms php-ge…
Joomscan
Open Source
Kali
OWASP Joomla vulnerability scanner. Detects Joomla version, components, modules, and templates with …