Created
February 26, 2024 07:25
-
-
Save mattfysh/ff3abbd883d21b8fde2c11999f7c3fd2 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
const mf = new Miniflare({ | |
script: ` | |
export default { | |
async fetch(request, env, ctx) { | |
let id = env.DOO.idFromName('foo') | |
return await env.DOO.get(id).fetch(request) | |
} | |
} | |
const SECONDS = 1000 | |
export class Doo { | |
constructor(state) { | |
this.storage = state.storage | |
} | |
async fetch(request) { | |
this.storage.setAlarm(Date.now() + 1 * SECONDS) | |
return new Response('Hello Miniflare!') | |
} | |
async alarm() { | |
console.log("Alarm running") | |
} | |
} | |
`, | |
durableObjects: { DOO: 'Doo' }, | |
log: new Log(), | |
verbose: true, | |
modules: true, | |
}) | |
const response = await mf.dispatchFetch('http://localhost:8787/') | |
console.log(await response.text()) // Hello Miniflare! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error message appears when the alarm is invoked, not when calling
setAlarm