Skip to content

Commit 8b206fe

Browse files
committed
Merge branch 'main' of https://github.com/the-hideout/tarkov-api into improve-origin-handling
2 parents a0df985 + 8f3e3a8 commit 8b206fe

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

.github/workflows/branch-deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
environment: "development"
5757

5858
# Post comment on PR with development deploy info
59-
- uses: GrantBirki/[email protected].0
59+
- uses: GrantBirki/[email protected].1
6060
if: ${{ steps.branch-deploy.outputs.continue == 'true' &&
6161
steps.branch-deploy.outputs.noop != 'true' &&
6262
steps.branch-deploy.outputs.environment == 'development' }}
@@ -82,7 +82,7 @@ jobs:
8282
apiToken: ${{ secrets.CF_API_TOKEN }}
8383

8484
# Post comment on PR with production deploy info
85-
- uses: GrantBirki/[email protected].0
85+
- uses: GrantBirki/[email protected].1
8686
if: ${{ steps.branch-deploy.outputs.continue == 'true' &&
8787
steps.branch-deploy.outputs.noop != 'true' &&
8888
steps.branch-deploy.outputs.environment == 'production' }}

.github/workflows/new-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@v4
2020

2121
- name: comment
22-
uses: GrantBirki/[email protected].0
22+
uses: GrantBirki/[email protected].1
2323
continue-on-error: true
2424
with:
2525
file: .github/new-pr-comment.md

index.mjs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import fetchWithTimeout from './utils/fetch-with-timeout.mjs';
2929
import { getNightbotResponse, useNightbotOnUrl } from './plugins/plugin-nightbot.mjs';
3030
import { getTwitchResponse } from './plugins/plugin-twitch.mjs';
3131
import { getLiteApiResponse, useLiteApiOnUrl } from './plugins/plugin-lite-api.mjs';
32+
import { getSpecialCache } from './plugins/plugin-use-cache-machine.mjs';
3233

3334
let dataAPI;
3435

@@ -84,11 +85,7 @@ async function graphqlHandler(request, env, ctx) {
8485
//return new Response(JSON.stringify({}), responseOptions);
8586
}
8687

87-
let specialCache = '';
88-
const contentType = request.headers.get('content-type');
89-
if (!contentType || !contentType.startsWith('application/json')) {
90-
specialCache = 'application/json';
91-
}
88+
const specialCache = getSpecialCache(request);
9289

9390
let key;
9491
// Check the cache service for data first - If cached data exists, return it

plugins/plugin-use-cache-machine.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import cacheMachine from '../utils/cache-machine.mjs';
22
import setCors from '../utils/setCors.mjs';
33

4-
function specialCache(request) {
4+
export function getSpecialCache(request) {
55
const contentType = request.headers.get('content-type');
6-
if (!contentType || !contentType.startsWith('application/json')) {
7-
return 'application/json';
6+
if (request.method === 'POST' && !contentType?.startsWith('application/json')) {
7+
//return 'application/json'; // don't enforce content type
88
}
99
return undefined;
1010
}
@@ -22,7 +22,7 @@ export default function useCacheMachine(env) {
2222
console.log(`Skipping cache check already performed by worker`);
2323
return;
2424
}
25-
const cachedResponse = await cacheMachine.get(env, {query: params.query, variables: params.variables, specialCache: specialCache(request)});
25+
const cachedResponse = await cacheMachine.get(env, {query: params.query, variables: params.variables, specialCache: getSpecialCache(request)});
2626
if (cachedResponse) {
2727
console.log('Request served from cache');
2828
request.cached = true;
@@ -82,7 +82,7 @@ export default function useCacheMachine(env) {
8282

8383
let ttl = request.data?.getRequestTtl(request.requestId) ?? 60 * 5;
8484

85-
const sCache = specialCache(request);
85+
const sCache = getSpecialCache(request);
8686
if (result.errors?.some(err => err.message === 'Unexpected error.')) {
8787
ttl = 0;
8888
} else if (result.errors?.some(err => err.message.startsWith('Syntax Error'))) {

0 commit comments

Comments
 (0)