Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPTIONS http method Added #6030

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/kit/src/runtime/server/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export async function render_page(event, route, options, state, resolve_opts) {
// for non-GET requests, first call handler in +page.server.js
// (this also determines status code)
try {
const method = /** @type {'POST' | 'PATCH' | 'PUT' | 'DELETE'} */ (event.request.method);
const method = /** @type {'POST' | 'PATCH' | 'PUT' | 'DELETE' | 'OPTIONS'} */ (
event.request.method
);
const handler = leaf_node.server[method];
if (handler) {
const result = await handler.call(null, event);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { json } from '@sveltejs/kit';

/** @type {import('@sveltejs/kit').RequestHandler} */
export function OPTIONS() {
return json({});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @type {import('./$types').Action} */
export function OPTIONS() {}
11 changes: 11 additions & 0 deletions packages/kit/test/apps/basics/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ test.describe('Endpoints', () => {
expect(headers.head).toEqual(headers.get);
});

test('OPTIONS request', async ({ request }) => {
const url = '/endpoint-output/options';

var response = await request.fetch(url, {
method: 'OPTIONS'
});

expect(response.status()).toBe(200);
expect(response.text()).toBe('{}');
});

// TODO all the remaining tests in this section are really only testing
// setResponse, since we're not otherwise changing anything on the response.
// might be worth making these unit tests instead
Expand Down
1 change: 1 addition & 0 deletions packages/kit/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export interface SSRNode {
PATCH?: Action;
PUT?: Action;
DELETE?: Action;
OPTIONS?: Action;
};
}

Expand Down