mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
25 lines
678 B
Go
25 lines
678 B
Go
package middleware
|
|
|
|
import "github.com/zap-proto/zip"
|
|
|
|
func AccessControl(allowOrigin string) zip.Handler {
|
|
return func(c *zip.Ctx) error {
|
|
// Set CORS headers for all requests.
|
|
c.SetHeader("Access-Control-Allow-Origin", allowOrigin)
|
|
c.SetHeader("Access-Control-Allow-Credentials", "true")
|
|
|
|
if c.Method() != "OPTIONS" {
|
|
return c.Next()
|
|
}
|
|
|
|
// Handle preflight OPTIONS request
|
|
reqHeaders := c.Header("Access-Control-Request-Headers")
|
|
|
|
c.SetHeader("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
|
c.SetHeader("Access-Control-Allow-Headers", reqHeaders)
|
|
c.SetHeader("Access-Control-Max-Age", "86400")
|
|
|
|
return c.NoContent(204)
|
|
}
|
|
}
|