Code Monkey home page Code Monkey logo

Comments (4)

gja avatar gja commented on June 2, 2024 1

I think this will probably be the direction we go in. As a start, I've opened #19, which just exports (by default) Worker and createApp.

from cloudflare-worker-local.

gja avatar gja commented on June 2, 2024 1

If you want to use chokidar, the new pseudocode would look something like this

const {createApp} = require("cloudflare-worker-local")

const app = createApp(fs.readFileSync("/path/to/worker.js"), {})
app.listen(3000);

chokidhar.watch("/path/to/worker.js")
  .on('change', () => fs.readFile('/path/to/worker.js', buffer => app.updateWorker(bufferToString(buffer))))

from cloudflare-worker-local.

gja avatar gja commented on June 2, 2024

Hmmm, Lots of food for thought. I think we should be exporting the following things:

  • startServer(pathToWorker, {port}) (this automatically will updating the worker on SIGHUP)
  • Worker
  • startTestServer(workerContents, upstreamBehavior)

I've updated the readme, turns out watching and listening for SIGHUP is actually much easier than I thought.

from cloudflare-worker-local.

jdanyow avatar jdanyow commented on June 2, 2024

In my experience so far using cloudflare-worker-local with packagers like parcel and rollup, nodemon hasn't worked well. It leads to complex npm scripts to ensure the packager has built the worker script prior to starting cloudflare-worker-local. Similar to remy/nodemon#1297 and remy/nodemon#797.

The sighup approach seems to be ok for scenarios where the worker source code is a single javascript file.

For increased flexibility I think it would be great if the CLI related logic (process.argv, SIGHUP and fs.readFile(pathToWorker)) was decoupled from the core logic (start server / update worker).

from cloudflare-worker-local.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.