Skip to content

Commit d9bf303

Browse files
Pass OPTIONS through Vite CORS to handler (#157)
Co-authored-by: ask-bonk[bot] <ask-bonk[bot]@users.noreply.github.com> Co-authored-by: southpolesteve <[email protected]> Co-authored-by: Steve Faulkner <[email protected]>
1 parent e04ea66 commit d9bf303

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/vinext/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,11 @@ hydrate();
12751275
const viteConfig: Record<string, any> = {
12761276
// Disable Vite's default HTML serving - we handle all routing
12771277
appType: "custom",
1278+
// Let OPTIONS requests pass through Vite's CORS middleware to our
1279+
// route handlers so they can set the Allow header and run user-defined
1280+
// OPTIONS handlers. Without this, Vite's CORS middleware responds to
1281+
// OPTIONS with a 204 before the request reaches vinext's handler.
1282+
server: { cors: { preflightContinue: true } },
12781283
// Externalize React packages from SSR transform — they are CJS and
12791284
// must be loaded natively by Node, not through Vite's ESM evaluator.
12801285
// Skip when targeting Cloudflare Workers (they bundle everything).

tests/e2e/app-router/api-routes.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,6 @@ test.describe("Route Handler HTTP Methods (OpenNext compat)", () => {
217217

218218
test("OPTIONS returns 204 with Allow header", async ({ request }) => {
219219
// Ref: opennextjs-cloudflare methods.test.ts "OPTIONS"
220-
// Note: vinext auto-generates OPTIONS responses based on exported methods,
221-
// so our explicit OPTIONS handler may or may not be called depending on
222-
// whether vinext intercepts before reaching the handler.
223-
// KNOWN GAP: vinext's auto-OPTIONS does not set the Allow header yet.
224-
test.fixme(true, "vinext auto-OPTIONS does not set Allow header — feature gap");
225220
const res = await request.fetch(`${BASE}/api/methods`, {
226221
method: "OPTIONS",
227222
});

0 commit comments

Comments
 (0)