Skip to content

Instantly share code, notes, and snippets.

@Mistic92

Mistic92/error Secret

Created April 11, 2022 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mistic92/fa4bfc7ee702a0e773b2e326fab1de56 to your computer and use it in GitHub Desktop.
Save Mistic92/fa4bfc7ee702a0e773b2e326fab1de56 to your computer and use it in GitHub Desktop.
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
}
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;
}
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
}
"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