ubiquity-os / ubiquity-os-kernel

1 stars 13 forks source link

Miniflare #2

Closed whilefoo closed 8 months ago

whilefoo commented 8 months ago

There are actually two options:

  1. Miniflare: we can use Cloudflare workers directly and use Miniflare as a development server which simulates a real worker environment.
  2. Hono: it's a platform agnostic that can run on Cloudflare workers, AWS lambda, Vercel...so it'd allow us to easily move to a different platform. It's meant to run on edge but it also supports running on Node.

I'm currently testing out the first option and it works when I build the worker but not when I build the local server because of some weird errors:

 [ERROR] Could not resolve "node:util"

    .yarn/cache/@fastify-busboy-npm-2.1.0-960844a007-f22c1e5c52.zip/node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js:4:25:
      4 │ const inherits = require('node:util').inherits
        ╵                          ~~~~~~~~~~~

  The Yarn Plug'n'Play manifest forbids importing "node:util" here because it's not listed as a
  dependency of this package:

    .pnp.cjs:659:31:
      659 │         "packageDependencies": [\
          ╵                                ~~

  The package "node:util" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
whilefoo commented 8 months ago

I've managed to run Miniflare but it shows some weird C++ errors whenever a request comes so we'll have to run Miniflare with wrangler v3 and run smee client separately.

0x4007 commented 8 months ago

I think yarn plug and play can be disabled either directly with a yarn config property or by using a different version of yarn. Perhaps that will help?

I did brief research now on both frameworks:

  1. Miniflare specifically states it's for development purposes only which leads me to believe that it is not a good idea to run it for production.
  2. I never heard of Hono before but maybe it seems okay.

Why can't we just go raw and use neither?

whilefoo commented 8 months ago

Miniflare can be used as a standalone library or as part of wrangler. And yes it's used for development when you're developing a Cloudflare worker. Basically when you run wrangler dev it runs Miniflare which simulates a Cloudflare worker environment.

I wanted to run Miniflare as standalone so we can run smee together, but since it's not working we will just have to run two commands, one to start smee and one to start wrangler dev server.

Also we don't need esbuild because wrangler dev and wrangler deploy automatically do everything, you just need to provide the JS/TS file.

With the latest commit I got the POC to work, it works by running a dev server and also by deploying to Cloudflare.

0x4007 commented 8 months ago

Can't get this to work at https://github.com/ubiquibot-pavlovcik/ubiquibot-sandbox/issues/1