elysiajs / elysia-cors

Plugin for Elysia that for Cross Origin Requests (CORs)
MIT License
29 stars 8 forks source link

DELETE method not allowed by default #49

Open GaspardCulis opened 6 months ago

GaspardCulis commented 6 months ago

The plugin's documentation specifies that the default allowed methods is basically the * wildcard. However when developing my API with this plugin I encountered CORS issues when trying to call a route using the DELETE method:

import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";

import * as gql from "./gql";
import * as media from "./media";

new Elysia()
    .use(cors())
    .group("/api", (app) =>
        app
            .post("/gql", gql.POST)
            .group("/media", (app) =>
                app
                    .get("", media.GET)
                    .post("", media.POST)
                    .delete("", media.DELETE), // This one
            ),
    )
    .listen(3000);

Fixed it by setting the methods parameter to *:

import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";

import * as gql from "./gql";
import * as media from "./media";

new Elysia()
    .use(cors({ methods: "*" })) // Here
    .group("/api", (app) =>
        app
            .post("/gql", gql.POST)
            .group("/media", (app) =>
                app
                    .get("", media.GET)
                    .post("", media.POST)
                    .delete("", media.DELETE),
            ),
    )
    .listen(3000);

Not a huge problem but kinda annoying

SaltyAom commented 2 months ago

Should have been fixed with 010f999, published on 1.0.4.