Skip to content

Commit

Permalink
fix: remove fetch cache, return byte array as body
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmpinto committed Oct 30, 2024
1 parent 1a2b2b8 commit 684eec0
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 543 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/next-on-fleek/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleek-platform/next-on-fleek",
"version": "1.15.2",
"version": "1.15.3",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/src/index.d.ts",
Expand Down
16 changes: 8 additions & 8 deletions packages/next-on-fleek/src/buildApplication/buildWorkerFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function buildWorkerFile(
{
outputDir,
workerJsDir,
nopDistDir,
// nopDistDir,
templatesDir,
customEntrypoint,
minify,
Expand Down Expand Up @@ -100,13 +100,13 @@ export async function buildWorkerFile(
outfile: outputFile,
});

await build({
...defaultBuildOpts,
entryPoints: ['adaptor.ts', 'cache-api.ts', 'kv.ts'].map(fileName =>
join(templatesDir, 'cache', fileName),
),
outdir: join(nopDistDir, 'cache'),
});
// await build({
// ...defaultBuildOpts,
// entryPoints: ['adaptor.ts', 'cache-api.ts', 'kv.ts'].map(fileName =>
// join(templatesDir, 'cache', fileName),
// ),
// outdir: join(nopDistDir, 'cache'),
// });

if (customEntrypoint) {
cliLog(`Using custom worker entrypoint '${customEntrypoint}'`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ export function generateGlobalJs(): string {
globalThis.fetch = async (...args) => {
const request = new Request(...args);
let response = await handleInlineAssetRequest(request);
const response = await handleInlineAssetRequest(request);
if (response) return response;
// response = await handleSuspenseCacheRequest(request);
// if (response) return response;
setRequestUserAgentIfNeeded(request);
return originalFetch(request);
Expand Down
5 changes: 2 additions & 3 deletions packages/next-on-fleek/templates/_worker.js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ async function adaptFleekRequestToFetch(
async function adaptFetchResponseToFleekResponse(
response: Response,
): Promise<FleekResponse> {
const body = await response.text();
const headers = {};
const headers: Record<string, string> = {};
response.headers.forEach((value, key) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand All @@ -156,6 +155,6 @@ async function adaptFetchResponseToFleekResponse(
return {
status: response.status,
headers,
body,
body: await response.bytes(),
};
}
126 changes: 0 additions & 126 deletions packages/next-on-fleek/templates/_worker.js/utils/cache.ts

This file was deleted.

9 changes: 1 addition & 8 deletions packages/next-on-fleek/templates/_worker.js/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { handleSuspenseCacheRequest } from './cache';

/**
* Patches the global fetch in ways necessary for Next.js (/next-on-fleek) applications
* to work
Expand All @@ -21,12 +19,7 @@ function applyPatch() {
globalThis.fetch = async (...args) => {
const request = new Request(...args);

let response = await handleInlineAssetRequest(request);
if (response) return response;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
response = await handleSuspenseCacheRequest(request);
const response = await handleInlineAssetRequest(request);
if (response) return response;

setRequestUserAgentIfNeeded(request);
Expand Down
4 changes: 0 additions & 4 deletions packages/next-on-fleek/templates/_worker.js/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { SUSPENSE_CACHE_URL } from '../../cache';

/**
* Adjusts the request so that it is formatted as if it were provided by Vercel
*
Expand All @@ -26,7 +24,5 @@ export function adjustRequestForVercel(request: Request): Request {
);
}

adjustedHeaders.set('x-vercel-sc-host', SUSPENSE_CACHE_URL);

return new Request(request, { headers: adjustedHeaders });
}
Loading

0 comments on commit 684eec0

Please sign in to comment.