Yes, another rosetta but for cors. Pardon me if some example goes unexpected. Please open issue or create pull request if some example is wrong.
This example also work with polka, and any express-like lib.
const express = require("express");
const cors = require("cors");
const app = express();
app.use(cors());
const express = require("express");
const cors = require("cors");
const app = express();
app.use(cors());
const Koa = require("koa");
const cors = require("@koa/cors");
const app = new Koa();
app.use(cors());
const Koa = require("koa");
const cors = require("@koa/cors");
const app = new Koa();
app.use(cors());
const fastify = require("fastify")();
fastify.register(require("fastify-cors"), { origin: true });
const fastify = require("fastify")();
fastify.register(require("fastify-cors"), { origin: true });
const restify = require("restify");
const server = restify.createServer();
server.use(restify.CORS());
const restify = require("restify");
const server = restify.createServer();
server.use(restify.CORS());
import { Application } from "https://deno.land/x/oak@v10.4.0/mod.ts";
const app = new Application();
app.use((ctx, next) => {
ctx.response.headers.set("access-control-allow-origin", "*");
return next();
});
import { Application } from "https://deno.land/x/oak@v10.4.0/mod.ts";
const app = new Application();
app.use((ctx, next) => {
ctx.response.headers.set("access-control-allow-origin", "*");
return next();
});
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
)
func main() {
r := chi.NewRouter()
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"*"},
}))
http.ListenAndServe(":8080", r)
}
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
)
func main() {
r := chi.NewRouter()
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"*"},
}))
http.ListenAndServe(":8080", r)
}
package main
import (
"net/http"
"github.com/rs/cors"
)
func main() {
mux := http.NewServerMux()
http.ListenAndServe(":8080", cors.Default().Handler(mux))
}
package main
import (
"net/http"
"github.com/rs/cors"
)
func main() {
mux := http.NewServerMux()
http.ListenAndServe(":8080", cors.Default().Handler(mux))
}
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func main() {
app := fiber.New()
app.Use(cors.New())
}
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func main() {
app := fiber.New()
app.Use(cors.New())
}
package main
import (
"github.com/gin-gonic/gin"
"github.com/gin-contrib/cors"
)
func main() {
r := gin.Default()
r.Use(cors.Default())
}
package main
import (
"github.com/gin-gonic/gin"
"github.com/gin-contrib/cors"
)
func main() {
r := gin.Default()
r.Use(cors.Default())
}