
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
github.com/AdhityaRamadhanus/fasthttpcors
Cors handler for fasthttp server
Read First |
Installation |
Usage |
License
Handling CORS in fasthttp
package main
import (
"log"
cors "github.com/AdhityaRamadhanus/fasthttpcors"
"github.com/valyala/fasthttp"
)
func main() {
withCors := cors.NewCorsHandler(cors.Options{
// if you leave allowedOrigins empty then fasthttpcors will treat it as "*"
AllowedOrigins: []string{"http://example.com"}, // Only allow example.com to access the resource
// if you leave allowedHeaders empty then fasthttpcors will accept any non-simple headers
AllowedHeaders: []string{"x-something-client", "Content-Type"}, // only allow x-something-client and Content-Type in actual request
// if you leave this empty, only simple method will be accepted
AllowedMethods: []string{"GET", "POST"}, // only allow get or post to resource
AllowCredentials: false, // resource doesn't support credentials
AllowMaxAge: 5600, // cache the preflight result
Debug: true,
})
if err := fasthttp.ListenAndServe(":8080", withCors.CorsMiddleware(RequestHandler)); err != nil {
log.Fatalf("Error in ListenAndServe: %s", err)
}
}
func RequestHandler(ctx *fasthttp.RequestCtx) {
ctx.SetContentType("plain/text")
ctx.SetStatusCode(200)
ctx.SetBodyString("OK")
}
MIT © [Adhitya Ramadhanus]
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.