
nodejs_compat and node_compat together. node_compat is an old and legacy way for wrangler to inject polyfills and globals that emulate Node.js things. nodejs_compat is actually real node.js support for various modules, straight from the runtime. It's the recommended way to do things nowadays.node_compat for the recommended pg driver today. You can use postgres.js with nodejs_compat, but it doesn't have full support with hyperdrive yet, mainly for things like caching.crypto.subtle which is built into all Workers, even without node compat: https://developers.cloudflare.com/workers/runtime-apis/web-crypto/#digestdigest using SHA-1name = "foo" and don't specify a name specifically under env.dev, then that Worker when ran with --env dev is now called foo-dev.request.url when calling fetch(), which wouldn't exist within the context of a scheduled worker?wrangler tail
A Worker must be able to be parsed and execute its global scope (top-level code outside of any handlers) within 400 ms. Worker size can impact startup because there is more code to parse and evaluate. Avoiding expensive code in the global scope can keep startup efficient as well.
class RedisCacheAside {
static getHashKey(_filter: any) {
let retKey = '';
if (_filter) {
retKey = 'CACHE_ASIDE_' + CryptoCls.hashString(JSON.stringify(_filter));
}
return retKey;
}
}
const query = {
color: {
equals: 'mint',
},
};
let data = RedisCacheAside.getHashKey(query);✘ [ERROR] TypeError: crypto_default.createHash is not a function
at CryptoCls.hashString
(file:///Users/nicolethomas/Desktop/Membership/hono/src/features/common/crypto.ts:7:21)
at RedisCacheAside.getHashKey
(file:///Users/nicolethomas/Desktop/Membership/hono/src/index.ts:59:45)
at null.<anonymous> (file:///Users/nicolethomas/Desktop/Membership/hono/src/index.ts:69:30)
at dispatch
(file:///Users/nicolethomas/Desktop/Membership/hono/node_modules/.pnpm/hono@4.2.2/node_modules/hono/dist/compose.js:29:23)
at null.<anonymous>
(file:///Users/nicolethomas/Desktop/Membership/hono/node_modules/.pnpm/hono@4.2.2/node_modules/hono/dist/compose.js:30:20)
at null.<anonymous> (file:///Users/nicolethomas/Desktop/Membership/hono/src/index.ts:31:9)
at dispatch
(file:///Users/nicolethomas/Desktop/Membership/hono/node_modules/.pnpm/hono@4.2.2/node_modules/hono/dist/compose.js:29:23)
at null.<anonymous>
(file:///Users/nicolethomas/Desktop/Membership/hono/node_modules/.pnpm/hono@4.2.2/node_modules/hono/dist/compose.js:30:20)
at poweredBy2
(file:///Users/nicolethomas/Desktop/Membership/hono/node_modules/.pnpm/hono@4.2.2/node_modules/hono/dist/middleware/powered-by/index.js:4:11)
at dispatch
(file:///Users/nicolethomas/Desktop/Membership/hono/node_modules/.pnpm/hono@4.2.2/node_modules/hono/dist/compose.js:29:23)async function hashString(input) {
const encoder = new TextEncoder();
const data = encoder.encode(input);
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
return bufferToHex(hashBuffer);
}
function bufferToHex(buffer) {
const view = new DataView(buffer);
let hex = '';
for (let i = 0; i < view.byteLength; i += 1) {
const byte = view.getUint8(i).toString(16);
hex += byte.padStart(2, '0');
}
return hex;
}[env.dev.vars]
API_HOST = "localhost"
API_PORT = "9000"
[env.production.vars]
API_HOST = "engine.corsa.club"
API_PORT = "443"[[queues.producers]]
queue = "stats"
binding = "QUEUE"
[[queues.consumers]]
queue = "stats"
max_batch_size = 10
max_batch_timeout = 30