Skip to content

Commit

Permalink
fix: 🐛 Add Content Type Header
Browse files Browse the repository at this point in the history
Adds Content Type header application/json on non GET requests
  • Loading branch information
enyineer committed Feb 28, 2024
1 parent e69d299 commit 6404953
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Have a look at the [Twitch API Reference](https://dev.twitch.tv/docs/api/referen

If the Endpoint is for example `PATCH https://api.twitch.tv/helix/channels`, send a PATCH Request to `http://localhost:6776/helix/channels` and the necessary Headers for Authorization will be added to your Request automatically.

Do not add any extra headers (eg. `Authorization` or `Client-Id`).
Do not add any extra headers (eg. `Authorization` or `Client-Id`). All headers sent with your request will be removed. All Methods other than `GET` will automatically get the `Content-Type: application/json` header.

## Reset twitch-api

Expand Down
8 changes: 6 additions & 2 deletions src/authGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ export const withAuthGate = async (request: Request) => {
url.hostname = "api.twitch.tv";
url.port = "443";

const body = request.body;
const method = request.method;

const headers = new Headers();
headers.set('Client-Id', clientId);
headers.set('Authorization', `Bearer ${accessToken}`);

const body = request.body;
const method = request.method;
if (method.toLowerCase() !== 'get') {
headers.set('Content-Type', 'application/json');
}

const initialResponse = await fetch(url.toString(), {
headers,
Expand Down

0 comments on commit 6404953

Please sign in to comment.