Skip to content

Commit

Permalink
Added content-type to response
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Sep 29, 2024
1 parent 1e1defb commit 391fe9f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ export async function parseBody<V extends Record<string, FormDataEntryValue>>(re

export function response<R>(status: StatusCodes = StatusCodes.OK, result?: R, error = false): Response {
const statusText: ReasonPhrases = ReasonPhrases[StatusCodes[status] as keyof typeof ReasonPhrases];
const headers = {
'Access-Control-Allow-Origin': '*',
};

const body: APIResponse<R> = { status, statusText, result, error };
return new Response(JSON.stringify(body), { status, statusText, headers });
return new Response(JSON.stringify(body), {
status,
statusText,
headers: {
'Access-Control-Allow-Origin': '*',
'content-type': 'application/json; charset=utf-8'
},
});
}

export function error(status: StatusCodes = StatusCodes.INTERNAL_SERVER_ERROR, message?: string): Response {
Expand Down

0 comments on commit 391fe9f

Please sign in to comment.