-
-
Save Mistic92/fa4bfc7ee702a0e773b2e326fab1de56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TypeError: ctx.waitUntil is not a function at line 0, col -2 | |
{ | |
"exceptionDetails": { | |
"columnNumber": -2, | |
"exception": { | |
"className": "TypeError", | |
"description": "TypeError: ctx.waitUntil is not a function", | |
"preview": { | |
"description": "TypeError: ctx.waitUntil is not a function", | |
"entries": null, | |
"overflow": false, | |
"properties": [ | |
{ | |
"name": "stack", | |
"subtype": null, | |
"type": "string", | |
"value": "TypeError: ctx.waitUntil is not a function", | |
"valuePreview": null | |
}, | |
{ | |
"name": "message", | |
"subtype": null, | |
"type": "string", | |
"value": "ctx.waitUntil is not a function", | |
"valuePreview": null | |
} | |
], | |
"subtype": "error", | |
"type": "object" | |
}, | |
"subtype": "error", | |
"type": "object", | |
"value": null | |
}, | |
"lineNumber": 0, | |
"text": "Uncaught (in response)", | |
"url": "undefined" | |
}, | |
"timestamp": 1649684199578 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function handleRequest( | |
request: Request, | |
ctx: ExecutionContext, | |
): Promise<Response> { | |
const cacheUrl = new URL(request.url); | |
const cacheKey = new Request(cacheUrl.toString(), request); | |
const cache = caches.default; | |
let response = await cache.match(cacheKey); | |
if (!response) { | |
console.log( | |
`Response for request url: ${request.url} not present in cache. Fetching and caching request.`, | |
); | |
response = await fetch("https://google.pl"); | |
response = new Response(response.body, response); | |
response.headers.append('Cache-Control', 's-maxage=10'); | |
ctx.waitUntil(cache.put(cacheKey, response.clone())); | |
} else { | |
response = new Response(response.body, response); | |
response.headers.append('Cache-Control', 's-maxage=10'); | |
response.headers.append('Reported', 'true'); | |
} | |
return response; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { handleRequest } from './handler'; | |
export default { | |
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | |
async fetch(request: Request, ctx: ExecutionContext, env: Env) { | |
console.log(` PARAMS ${JSON.stringify(env)}`) | |
return handleRequest(request, ctx); | |
}, | |
}; | |
interface Env { | |
ENVIRONMENT: string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"devDependencies": { | |
"@cloudflare/workers-types": "3.4.0", | |
"@rollup/plugin-commonjs": "21.0.3", | |
"@rollup/plugin-node-resolve": "13.1.3", | |
"@rollup/plugin-typescript": "8.3.1", | |
"@rollup/plugin-dynamic-import-vars": "1.4.2", | |
"@types/jest": "^26.0.23", | |
"@types/service-worker-mock": "2.0.1", | |
"@typescript-eslint/eslint-plugin": "^4.16.1", | |
"@typescript-eslint/parser": "^4.16.1", | |
"eslint": "^7.21.0", | |
"eslint-config-prettier": "^8.1.0", | |
"eslint-config-typescript": "^3.0.0", | |
"ignore-loader": "^0.1.2", | |
"jest": "^27.0.1", | |
"prettier": "^2.3.0", | |
"rollup": "2.70.1", | |
"rollup-plugin-terser": "7.0.2", | |
"service-worker-mock": "^2.0.5", | |
"ts-jest": "^27.0.1", | |
"ts-loader": "9.2.8", | |
"typescript": "^4.3.2" | |
}, | |
"dependencies": { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment