Skip to content

Commit

Permalink
Apply the change to search response as well
Browse files Browse the repository at this point in the history
Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>
  • Loading branch information
damianstasik committed Aug 30, 2024
1 parent bdaddb0 commit 6c6580e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions search/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ async function getClient(databaseUrl: string): Promise<Client> {
return client;
}

function applyCorsHeaders(response: Response) {
response.headers.set('Access-Control-Allow-Origin', '*');
response.headers.set('Access-Control-Allow-Methods', 'GET');
return response;
}

async function fetchData(client: Client, queryParam: string, ctx: ExecutionContext): Promise<Response> {
try {
const results = await query(client, queryParam);
Expand All @@ -30,13 +36,9 @@ async function handleSearchRequest(request: Request, env: Env, ctx: ExecutionCon
}

const client = await getClient(env.DATABASE_URL);
return await fetchData(client, validation.queryParam, ctx);
}
const response = await fetchData(client, validation.queryParam, ctx);

function applyCorsHeaders(response: Response) {
response.headers.set('Access-Control-Allow-Origin', '*');
response.headers.set('Access-Control-Allow-Methods', 'GET');
return response;
return applyCorsHeaders(response);
}

async function serveR2Object(request: Request, env: Env, objectKey: string) {
Expand Down

0 comments on commit 6c6580e

Please sign in to comment.