sveltejs / sveltejs/kit

Allow adding additional functions to `_worker.js`

Open
#10,496 22 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #13207 by @thomasfosterau — closed without merging
  • #15574 by @teemingc — closed without merging
  • #15627 by @teemingc — closed without merging
pkg:adapter-cloudflare
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Cloudflare Queues is currently in open beta. It would be nice to be able to consume messages from the same worker that handles HTTP requests, as opposed to having to creating a separate worker. For a worker to consume from a queue a new queue function needs to be defined on the worker object.

// worker.js
export default {
  async fetch(request, env, ctx) {
    // Handle request...
  },
  async queue(batch, env) {
    // Process batch...
  },
};

Currently there is no easy way to add this queue function to the woker object in the generated _worker.js.

Other Cloudflare services such as Email Workers follow a similar approach.

Describe the proposed solution

I'd suggest a special src/cloudflare-worker.js file which would export functions such as queue which then during compilation get added to the _worker.js file.

// src/cloudflare-worker.js

export const queue = (batch, env) =>  // Process batch...
Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating how the generated _worker.js is produced and review the proposed src/cloudflare-worker.js entry point. Check the closed pull requests linked to this issue for prior implementation context. Done means additional worker functions such as queue are available in the generated worker alongside HTTP handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.