GithubHelp home page GithubHelp logo

skymethod / denoflare Goto Github PK

View Code? Open in Web Editor NEW
646.0 6.0 32.0 4.47 MB

Develop, test, and deploy Cloudflare Workers with Deno.

Home Page: https://denoflare.dev

License: MIT License

TypeScript 86.21% HTML 7.23% JavaScript 6.56%
deno cloudflare-workers

denoflare's People

Contributors

arisris avatar faeyumbrea avatar johnspurlock-skymethod avatar justingrote avatar nanai10a avatar wcaleniewolny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

denoflare's Issues

Error running script Error: Bad module.default: undefined

Hi, I am getting the following error when doing : "denoflare serve main"

Compiling https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli-webworker/worker.ts into worker
contents...
Bundled https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli-webworker/worker.ts (process) in 105ms
runScript: /src/index.ts
Bundled /src/index.ts (process) in 38ms
worker: start
Error running script Error: Bad module.default: undefined
at Function.create (blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:578:49)
at async Function.start (blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:679:50)
at async blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:2781:22
at async RpcChannel.receiveMessage (blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:39:36)
at async self.onmessage (blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:2810:13)
error: Failed at the denoflare script

Deno 1.28.3
denoflare v0.5.11

scripts.ts:

export default {
    "scripts": {
      "denoflare": "deno run --unstable --allow-run --allow-write --allow-read --allow-net --allow-env https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli.ts"
    }
};

.denoflare

{
  "$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/config.schema.json",
  "scripts": {
    "main": {
      "path": "/src/index.ts",
      "localPort": 3838
    }
  },
  "profiles": {
    "myprofile": {
      "accountId": "xxxxxxxxxxxx",
      "apiToken": "xxxxxxxxx"
    }
  }
}

index.ts

console.log('hello world');

Deno.spawn is not a function when deploying / serving any worker

I'm getting the error with the callstack:

error: Uncaught (in promise) TypeError: Deno.spawn is not a function
    const rt = await Deno.spawn(command, options) as any;
                          ^
    at spawn (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/spawn.ts:12:27)
    at runDenoBundle (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/deno_bundle.ts:67:53)
    at denoBundle (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/deno_bundle.ts:35:45)
    at async bundle (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/bundle.ts:104:35)
    at async Function.start (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/worker_manager.ts:38:43)
    at async createLocalRequestServer (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/cli_serve.ts:155:35)
    at async Object.serve [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/cli_serve.ts:188:32)
    at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/cli_command.ts:104:13)
    at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/cli.ts:33:5

When attempting to publish or serve any worker.

My specs
deno 1.32.4 (release, aarch64-apple-darwin)
v8 11.2.214.9
typescript 5.0.3

OS: Macbook Pro M1

no KV?

Hi,

Seeing that there are config options for KV, I assumed denoflare supported it.

I gave it a simple test but get RpcKVNamespace.put not implemented.

Looking at the code, I see that get is partially implemented, but put, list, delete, etc are empty.

Is that correct?

Etag & CORS issues in public buckets

Hi there, the public read has a couple of issues.

  1. The second time you try to download a file you will recieve this error, the string will be different. I have tried this with multiple files. Status Code: 500
    TypeError: Conditional ETag should not be wrapped in quotes ("d03c2f258e9fc6e7236f61c130ed1e48").

  2. Range files, specifically m3u8 video files don't work.

Using this: denoflare push https://raw.githubusercontent.com/skymethod/denoflare/v0.5.4/examples/r2-public-read-worker/worker.ts

public R2 issues

Hi,

This looks like an amazing project. Thanks in advance for taking it on and offering up.

I found denoflare while looking for worker script to make an R2 bucket public.

When I follow the example at: https://denoflare.dev/examples/r2-public-read

And, then create a .denoflare jsonc as explained there (but without a custom domain definition and WITH a directoryListing flag) and then do denoflare serve <my-worker-name> I get a "There is nothing here yet" page.

My R2 bucket has only one '/media' directory in it with many images under it.

So, if I got to https://..workers.dev/media/ I also get the "There is nothing here yet" page.

However, if I run locally with denoflare server <my-worker-name>, the http://localhost:8080/ says "file not found"

BUT, the http://localhost:8080/media/ does work and shows the image file.

Is it maybe a configuration error?

Deno Deploy as an optional target in `denoflare push`

Module-based Cloudflare workers that use no environment bindings to cf-specific services (or have graceful fallbacks) basically work unmodified on Deno Deploy.

With an entry point wrapper along the lines of:

import { serve } from 'https://deno.land/[email protected]/http/server.ts';
import { default as worker } from './worker.ts'; // the cloudflare module-based worker entry point

serve((req, init) => {
    const env = Deno.env.toObject();
    if (init.remoteAddr.transport === 'tcp') {
        const newHeaders = new Headers(req.headers);
        newHeaders.append('cf-connecting-ip', init.remoteAddr.hostname);
        req = new Request(req, { headers: newHeaders });
    }
    return worker.fetch(req, env);
});

Since Deploy has an api deployment option, we should add Deploy as a target option and generate this entrypoint wrapper automatically.

denoflare push uploads bundle with no registered event handlers

We are attempting to combine Kian's s3-to-r2 worker and denoflare's r2-presigned-url worker.

We have implemented a simple worker based on Kian's that first calls the r2-presigned-url worker's fetch() method before doing it's thing.

We are unable to denoflare push this worker to CloudFlare and have narrowed the cause down to a minimal worker to demonstrate the issue:

import { AwsClient } from "aws4fetch";

export default {
    async fetch(request: Request): Promise<Response> {
        return new Response()
    }
}

The error is:

$ denoflare push hello-local \
    --account-id "$CF_ACCOUNT_ID" \
    --api-token "$CF_API_TOKEN" \
    --custom-domain "$WORKER_BUCKET_NAME.$WORKER_ENDPOINT" \
    --name "$WORKER_NAME"
bundling FOO-r2-presigned-url-worker into bundle.js...
bundle finished (process) in 38ms
computed bindings in 0ms
putting module-based worker FOO-r2-presigned-url-worker... (0bytes) (20bytes compressed)
error: Uncaught (in promise) Error: putScript failed: status=400, errors=10068 The uploaded script has no registered event handlers.
    { code: 10068, message: "The uploaded script has no registered event handlers." }
    at execute (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/cloudflare_api.ts:1343:15)
    at async putScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/cloudflare_api.ts:97:13)
    at async buildAndPutScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_push.ts:86:9)
    at async Object.push [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_push.ts:120:5)
    at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_command.ts:104:13)
    at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli.ts:33:5

If we comment out the AwsClient import, it is able to deploy:

$ denoflare push hello-local \
    --account-id "$CF_ACCOUNT_ID" \
    --api-token "$CF_API_TOKEN" \
    --custom-domain "$WORKER_BUCKET_NAME.$WORKER_ENDPOINT" \
    --name "$WORKER_NAME"
bundling FOO-r2-presigned-url-worker into bundle.js...
bundle finished (process) in 35ms
computed bindings in 0ms
putting module-based worker FOO-r2-presigned-url-worker... (262bytes) (188bytes compressed)
put script FOO-r2-presigned-url-worker in 807ms
ensuring FOO points to FOO-r2-presigned-url-worker...
bound worker to custom domain in 743ms

Kian's original script uses aws4fetch, so we need that. denoflare push fails with the same error on Kian's original script.

We can deploy Kian's original script with wrangler, but we can't import and use the denoflare r2-presigned-url worker code because CloudFlare then claims the module doesn't exist. Kian on Discord says "Wrangler wouldn't bundle URL imports, it just uses esbuild"

We found #38 (comment) and we tried adding isolationLevel: "none" to the config and switched to denoflare serve which yielded a different error:

$ denoflare serve hello-local
error: Uncaught (in promise) TypeError: Relative import path "index2.ts" not prefixed with / or ./ or ../ from "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/module_worker_execution.ts"
        const module = await import(scriptPath);
                       ^
    at async Function.create (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/module_worker_execution.ts:19:24)
    at async Function.start (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/worker_execution.ts:39:50)
    at async createLocalRequestServer (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_serve.ts:154:20)
    at async Object.serve [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_serve.ts:190:32)
    at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_command.ts:104:13)

We tried switching to an absolute path, but it seems to want to combine that absolute (or relative) path with a GitHub URL that doesn't work:

$ denoflare serve hello-local
Download https://raw.githubusercontent.com/Users/FOO/cloudflare-worker-s3-to-r2-migration/src/index2.ts
error: Uncaught (in promise) TypeError: Module not found "https://raw.githubusercontent.com/Users/FOO/cloudflare-worker-s3-to-r2-migration/src/index2.ts".
        const module = await import(scriptPath);
                       ^
    at async Function.create (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/module_worker_execution.ts:19:24)
    at async Function.start (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/worker_execution.ts:39:50)
    at async createLocalRequestServer (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_serve.ts:154:20)
    at async Object.serve [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_serve.ts:190:32)
    at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_command.ts:104:13)
    at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli.ts:33:5

We were also unsuccessful in an attempt to locate the bundle.js file that is supposedly built, so we can see what has happened and why it no longer has any registered event handlers.

I'm not sure what else to try now except build a version of denoflare that uses local/relative import paths that are compatible with wrangler?

Error while fetching R2 file

Hello,

a few days ago I created a simple CDN with denoflare and cloudflare r2. But today the r2 request failed with the error: Error servicing request Error: Expected content-length header

Error servicing request Error: Expected content-length header
    at getExpectedHeader (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/api_r2_bucket.ts:180:11)
    at new HeadersBasedR2Object (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/api_r2_bucket.ts:236:22)
    at new ResponseBasedR2ObjectBody (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/api_r2_bucket.ts:268:9)
    at ApiR2Bucket.get (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/api_r2_bucket.ts:61:16)
    at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/rpc_r2_bucket.ts:39:67
    at async RpcChannel.receiveMessage (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/rpc_channel.ts:41:36)
    at async Worker.worker.onmessage (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/worker_manager.ts:67:17)

This error is only happen when the requested file actually exists on the r2 bucket.

I tried to replace the api key with a new one but the error still happen.

Is this a known issue or am I doing something wrong?

main.ts

export default {
  fetch: async (
    req: IncomingRequestCf,
    env: WorkerEnvironment,
    ctx: ModuleWorkerContext
  ): Promise<Response> => {
    const file = await env.bucket.get('assets/logo.svg');
    return new Response('ok');
  },
};

export interface WorkerEnvironment {
  bucket: R2Bucket;
}

.denoflare

{
  "$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/config.schema.json",
  "scripts": {
    "cdn": {
      "path": "./modules/cdn/main.ts",
      "localPort": 8081,
      "bindings": {
        "bucket": {
          "bucketName": "storage"
        }
      }
    }
  },
  "profiles": {
    "default": {
      "default": true,
      "accountId": "xxx",
      "apiToken": "xxx"
    }
  }
}

D1 Bindings do not work as regular bindings until end of Beta

This is less a bug/issue of denoflare as it is a "why tho" on part of Cloudflare.

The D1 Runtime API does not actually exist on the Cloudflare Servers right now.

What wrangler does when you have a D1 Binding is prefix the whoooole thing with some fun static text and then include this mess:
https://github.com/cloudflare/wrangler2/blob/8986ccb3eb285f5a50cdd987d5e17f9eb6df3480/packages/wrangler/templates/d1-beta-facade.js
Making it the new script entry point after replacing the variable in it.

If you want to support D1 bindings magically, you'll have to bundle this file with in the denoflare build process. Which sounds like a lot of pain that can be avoided.
I think it'll be easier to just add a blurb to the docs until Cloudflare decides to actually publish a D1 Runtime API to their servers.

Cannot use Async fetch prototype like Cloudflare allows

Here is the code who produce the error:
error: Uncaught (in promise) Error: putScript failed: status=400, errors=10068 The uploaded script has no registered event handlers.

export default {
  async fetch(request: Request): Promise<Response> {
    // fake await to simulate a slow response
    await new Promise(resolve => setTimeout(resolve, 1000))
    return new Response('Hello, world!')
  },
}

The code without async work at upload.
The code with async work in Cloudflare workers, so it should be allowed in Denoflare.

Deno.emit is not a function

Thank you for creating this!

I run denoflare serve hello-local & the result is

Compiling https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli-webworker/worker.ts into worker contents...
error: Uncaught (in promise) TypeError: Deno.emit is not a function
    const result = await Deno.emit(rootSpecifier, {
                              ^
    at emit (https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/emit.ts:3:31)
    at Function.start (https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/worker_manager.ts:30:32)
    at createLocalRequestServer (https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/cli_serve.ts:122:55)
    at serve (https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/cli_serve.ts:155:38)
    at async https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/cli.ts:16:13

Provide TS types for non-standard `fetch` request init `cf` object

The cloudflare typings for the fetch seems to be different in cloudflare:
Example:

 let response = await fetch(request, {
      cf: {
        // Always cache this fetch regardless of content type
        // for a max of 5 seconds before revalidating the resource
        cacheTtl: 5,
        cacheEverything: true,
        //Enterprise only feature, see Cache API for other plans
        cacheKey: someCustomKey,
      },
    });```
In deno the following error occurs:

No overload matches this call.
Overload 1 of 2, '(input: string | URL | Request, init?: RequestInit | undefined): Promise', gave the following error.
Argument of type '{ cf: RequestInitCfProperties; }' is not assignable to parameter of type 'RequestInit'.
Object literal may only specify known properties, and 'cf' does not exist in type 'RequestInit'. Overload 2 of 2, '(input: string | URL | Request, init?: (RequestInit & { client: HttpClient; }) | undefined): Promise', gave the following error.
Argument of type '{ cf: RequestInitCfProperties; }' is not assignable to parameter of type 'RequestInit & { client: HttpClient; }'.
Object literal may only specify known properties, and 'cf' does not exist in type 'RequestInit & { client: HttpClient; }'.deno-ts(2769)```

Fetch init.signal error

Error: packRequest: init.signal
    at packRequest (blob:null/74878e83-1a35-4f3c-a67a-93d94adee03e:1003:50)
    at blob:null/74878e83-1a35-4f3c-a67a-93d94adee03e:765:22
    at fetchWithTimeout (blob:null/b9119e73-2aec-4ae2-bd38-1b596890bc68:32228:28)
    at fallback (blob:null/b9119e73-2aec-4ae2-bd38-1b596890bc68:32263:29

Code to reproduce:

async function fetchWithTimeout(resource: RequestInfo, options: RequestOptions = {}): Promise<Response> {
  const controller = new AbortController()

  console.log('fetch', resource)
  const { timeout = 5000 } = options
  console.log('timeout', timeout)

  const id = setTimeout(() => {
    console.log('timeout')
    controller.abort()
  }, timeout)
  const response = await fetch(resource, {
    signal: controller.signal,
  })
  clearTimeout(id)
  return response
}

Line causing: here

How can I configure triggers?

first of all thanks for such amazing project, but I don't find a reference to see how can I configure my worker to use triggers.

Deprecated --unstable flag warning

The documentation says to install with --unstable, but as of Deno 1.40 this now results in a warning upon each use.

The `--unstable` flag is deprecated and will be removed in Deno 2.0. Use granular `--unstable-*` flags instead.
Learn more at: https://docs.deno.com/runtime/manual/tools/unstable_flags

I installed without --unstable and it seems to be working OK, which unstable features are used exactly? Couldn't determine in a quick perusal. (Deno reference and available flags here: https://docs.deno.com/runtime/manual/tools/unstable_flags)

Cannot use npm specifier

If i change one import in my codebase to the new syntax for npm specifier in Deno.
Like below:
CleanShot 2024-02-02 at 03 39 50@2x
I get this error on the deploy step:
CleanShot 2024-02-02 at 03 39 56@2x
it seems it's not supported

Config Json schema does not propose `ServiceBinding`

When creating the denoflare configuration while referring to the schema https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/common/config.schema.json suggested in the denoflare configuration (https://denoflare.dev/cli/configuration), we cannot bind a service to our configuration in the bindings section. The only options proposed are in the image attached.

Is there something we are missing in order to bind a worker to another service?

image

Documentation unclear

Hi. I'm interested in using this project, but the documentation puzzles me. There is no clear path from installation to running and deploying a worker.

Why do I need to define my projects in the .denoconfig file in the home folder? Isn't it more intuitive to create a config file at the root of the project?

No stacktrace sources in `denoflare serve`

When running a script via denoflare serve, error stracktraces don't have source file path:

Error servicing request Error: DenoflareResponse.statusText not implemented
    at DenoflareResponse.get statusText (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:479:15)
    at WorkerRouter.#fireError (blob:null/2f968119-42b1-4463-a069-f31f715a2813:774:78)
    at WorkerRouter.#route (blob:null/2f968119-42b1-4463-a069-f31f715a2813:768:28)
    at Object.fetch (blob:null/2f968119-42b1-4463-a069-f31f715a2813:958:27)
    at ModuleWorkerExecution.fetch (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:629:34)
    at WorkerExecution.fetch (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:727:34)
    at blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:3107:41
    at RpcChannel.receiveMessage (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:39:42)
    at self.onmessage (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:3146:30)
    at wrappedHandler (ext:deno_web/02_event.js:1401:12)

importText under windows breaks when using a subdirectory

How to reproduce:

  1. Have a file in a directory other than the script file. (i.e. src/files)
  2. Reference the file using importText
  3. Run "push" under Windows

Expected Result:
From testing this in WSL, it should just automagically work.

Actual Result:
Under Windows, probably due to the whole \ instead of / thing. You get a broken import ("filefile.txt" does not exist).
It works perfectly fine if the script and file are in the same subfolder though.

canot serve example

i follow you tutorial https://denoflare.dev/guides/serve
and i serve project
but get error message

Error running script Error: Bad module.default: undefined
at Function.create (blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:573:49)
at async Function.start (blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:672:50)
at async blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:2504:22
at async RpcChannel.receiveMessage (blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:39:36)
at async self.onmessage (blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:2532:13)

my .denoflare file

{
    "$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.7/common/config.schema.json",
    "scripts": {
        "hello-local": {
            "path": "main.ts",
            "localPort": 3030
        }
    },
    "profiles": {
        "account1": {
            // your cloudflare account id
            "accountId": "6b9a6f27ffddd42d8f9b0f16d655e7fe",
            // your cloudflare api token
            "apiToken": "CxRhXkwP35y0rKm5fjJ2_eIiWjkalz8Z8t7Pb-yE"
        }
    }
}

Plain .js files not working: Script did not add a fetch listener

With the following test.js, denoflare won't start.

% cat test.js
export default {
    async fetch (request, env) {
	return new Response ('hello\n');
    },
};
% ../bin/denoflare serve test.js
Compiling https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli-webworker/worker.ts into worker contents...
✅ Granted write access to "/var/folders/dl/2c03sbp56t3djlcsq246h9v80000gn/T/".
Bundled https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli-webworker/worker.ts (process) in 1219ms
runScript: test.js
worker: start
Error running script Error: Script did not add a fetch listener
    at Function.create (blob:null/13008441-80e2-4428-9ef9-bead231069a1:614:48)
    at async Function.start (blob:null/13008441-80e2-4428-9ef9-bead231069a1:679:125)
    at async blob:null/13008441-80e2-4428-9ef9-bead231069a1:2781:22
    at async RpcChannel.receiveMessage (blob:null/13008441-80e2-4428-9ef9-bead231069a1:39:36)
    at async self.onmessage (blob:null/13008441-80e2-4428-9ef9-bead231069a1:2810:13)

.ts files works fire, however. Seems plain .js files are not supported.

Documentation request: tutorials at the beginner level

I'd like to begin using Denoflare but with a lack of experience using Deno, I'm lost after finishing the Hello World tutorial. It would be great if there were a few more tutorials that took users to the next step after Hello World. I was the first person to use the denoflare tag on Stack Overflow so I couldn't find much help there either. Here is my question on Stack Overflow:

But the issue here is a request for more beginner documentation. Thank you for your work on this project.

putScript failed when pushing hello-wasm-worker

I try to push hello-wasm-worker, but I couldn't with the error putScript raised.
I seem importWasm function cause this error, but I couldn't understand the details...

Error log

bundling test-wasm-worker into bundle.js...
bundle finished (process) in 361ms
computed bindings in 1ms
putting module-based worker test-wasm-worker... (38.2kb) (6.3kb compressed)
error: Uncaught (in promise) Error: putScript failed: status=400, errors=10021 Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.
  at line 0

    {
      code: 10021,
      message: "Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values..."
    }
    at execute (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/cloudflare_api.ts:1044:15)
    at async putScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/cloudflare_api.ts:96:13)
    at async buildAndPutScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/cli_push.ts:83:9)
    at async Object.push [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/cli_push.ts:117:5)
    at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/cli_command.ts:104:13)
    at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/cli.ts:33:5

Deploy command

denoflare push test-wasm-worker --config .denoflare.jsonc --account-id $CLOUDFLARE_ACCOUNT_ID --api-token $CLOUDFLARE_API_TOKEN

.denoflare.jsonc

{
    // This jsonc file supports comments and trailing commas!

    // optional schema to get auto-completions when editing this file in vscode, etc
    "$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/config.schema.json",

    // define script configurations by name, and their associated bindings and options
    // you can then simply refer to them by name in your denoflare commands
    // note the same script source can be specified more than once with different configurations (local vs prod etc)
    "scripts": {
        "test-wasm-worker": {
            "path": "hello.ts",
            "localPort": 3002
        }
    }
}

Environments

  • Mac OS Monterey (M1)
  • deno 1.23.4
  • denoflare 0.5.3

Worker type definitions?

I'm trying denoflare for cf worker development and having issues with the type definitions. The official type definition file does not play with deno as it contains many conflicting definitions.

I have found this file in the repo but it seems to be different from the official definitions. For example, the get method of KVNamespace can be used with only 1 argument but raises type error when using the definition from this file.

I wonder what's the recommended / common practice here. Thanks.

Cannot fetch with body in denoflare serve

When I try to fetch using body, e.g.

await fetch("https://site...", {
      "method": "POST",
      "body": JSON.stringify({})
})

throw this:

catch Error: packRequest: init.body
    at packRequest (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:923:48)
    at blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:720:22
    at apo (blob:null/09d901da-479f-4908-9df0-1021d32d744e:7:25)
    at serveTitle (blob:null/09d901da-479f-4908-9df0-1021d32d744e:4557:25)
    at async Object.fetch (blob:null/09d901da-479f-4908-9df0-1021d32d744e:4569:28)
    at async ModuleWorkerExecution.fetch (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:584:16)
    at async WorkerExecution.fetch (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:682:16)
    at async blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:2619:30
    at async RpcChannel.receiveMessage (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:39:36)
    at async self.onmessage (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:2656:13)

Help with `r2-presigned-url-worker` example.

The r2-presigned-url-worker example looks like exactly what I need (thanks!) to implement a worker that retains the existing presigned URL authorization functionality on a private bucket. But I am unable to run it locally via deno serve or publish it example to CloudFlare.

Steps:

  • Install deno via brew install deno per docs
  • Install denoflare via deno install --unstable --allow-read --allow-net --allow-env --allow-run --name denoflare --force https://raw.githubusercontent.com/skymethod/denoflare/v0.5.8/cli/cli.ts per docs
    • I also tried installing https://raw.githubusercontent.com/skymethod/denoflare/master/cli/cli.ts
  • Clone this repo via git clone https://github.com/skymethod/denoflare.git and cd to denoflare/examples/r2-presigned-url-worker
  • Create a .denoflare file per docs, but with "path": "worker.ts" instead of "path": "index.ts", and provide accountId and apiToken
  • Run denoflare serve hello-local

I get this error:

$ denoflare serve hello-local
Compiling https://raw.githubusercontent.com/skymethod/denoflare/31db528115dc6260ac09ba2abd6c9a5aa8709b8a/cli-webworker/worker.ts into worker contents...
✅ Granted write access to "/var/folders/2j/ymfzssrx66gg87hypqbw1ptr0000gn/T/".
Bundled https://raw.githubusercontent.com/skymethod/denoflare/31db528115dc6260ac09ba2abd6c9a5aa8709b8a/cli-webworker/worker.ts (process) in 15413ms
runScript: worker.ts
Bundled worker.ts (process) in 547ms
worker: start
Error running script TypeError: Cannot set property caches of #<DedicatedWorkerGlobalScope> which has only a getter
    at defineGlobalCaches (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:507:33)
    at defineModuleGlobals (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:490:5)
    at Function.create (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:557:9)
    at Function.start (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:674:78)
    at blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:2561:44
    at RpcChannel.receiveMessage (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:39:42)
    at self.onmessage (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:2589:30)
    at wrappedHandler (deno:ext/web/02_event.js:1362:14)
    at innerInvokeEventListeners (deno:ext/web/02_event.js:755:9)
    at invokeEventListeners (deno:ext/web/02_event.js:795:7)

I also tried to take an existing worker (kian's s3-to-r2-migration which is already working (but allows public access) and import the r2-presigned-url-worker example so that I could first execute your computeResponse() and fallback to kian's code:

import r2PresignedUrlWorker from "https://raw.githubusercontent.com/skymethod/denoflare/master/examples/r2-presigned-url-worker/worker.ts";

...

export default {
    async fetch(request: Request, env: Env, ctx: EventContext<any, any, any>): Promise<Response> {
        const response = await r2PresignedUrlWorker.fetch(request, env);
        if (response.status == 200) {
            return response;
        }

        ... fallback to kian's code

But when I try to publish this:

$ wrangler publish
 ⛅️ wrangler 2.1.10 
--------------------
Your worker has access to the following bindings:
- R2 Buckets:
  - R2: ...
- Vars:
  - AWS_DEFAULT_REGION: "auto"
  - AWS_S3_BUCKET: "..."
  - AWS_S3_BUCKET_SCHEME: "https:"
  - AWS_SERVICE: "s3"
Total Upload: 15.42 KiB / gzip: 4.56 KiB

✘ [ERROR] A request to the Cloudflare API (/accounts/.../workers/scripts/s3-to-r2) failed.

  Uncaught Error: No such module
  "https:/raw.githubusercontent.com/skymethod/denoflare/master/examples/r2-presigned-url-worker/worker.ts".
    imported from "index.js"
   [code: 10021]

  
  If you think this is a bug, please open an issue at:
  https://github.com/cloudflare/wrangler2/issues/new/choose

Can you please provide some guidance on how to run and publish this example as-is, and how I might import and use it within an existing worker?

Error running script SyntaxError: Identifier 'concat' has already been declared at blob:null/fc6d65b1-68e1-4492-9180-8f3271ba2cd7:824:1

In my Deno grammY application, when I call apiThrottler function from @grammyjs/transformer-throttler package, and run $ denoflare serve src/prod-cloudflare.ts, I've got the following error:

Error running script SyntaxError: Identifier 'concat' has already been declared at blob:null/fc6d65b1-68e1-4492-9180-8f3271ba2cd7:824:1
    at async Function.create (blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:563:24)
    at async Function.start (blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:679:50)
    at async blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:2781:22
    at async RpcChannel.receiveMessage (blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:39:36)
    at async self.onmessage (blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:2810:13)

Context:

But, on Node.js, and using it (@grammyjs/transformer-throttler) via NPM – it works OK (it means I don't get this error).

`denoflare serve` in local isolation mode hangs when using importText/Binary/Wasm on Deno v1.34.2

calling import() in ModuleWorkerExecution.create hangs indefinately starting in deno v1.34.2 when using importText, importBinary, or importWasm

Workaround for now is to stay on Deno v1.34.1.

Looks to be a possible Deno regression, as the entire module appears to be loaded and init successfully, including fetched resources over rpc (importX calls are translated to fetches when not on Cloudflare), just never returns to the caller.

Will look to create a small repro case and send over to the Deno folks.

Hyperdrive support via deno-postgres

I have a index.js script which imports postgres drivers:

import { Client, Pool } from "https://deno.land/x/postgres/mod.ts";

When running I get:

mlanza@Marios-MacBook-Air df-ex % denoflare serve hello-local
Compiling https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli-webworker/worker.ts into worker contents...
Compiled https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli-webworker/worker.ts into worker contents in 630ms
runScript: index.js
worker: start
Error running script TypeError: Requires net access to "deno.land", run again with the --allow-net flag
    at blob:null/33e03125-26c1-4b7b-88c2-5e4888b766d3:1:30
    at async Function.create (blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:428:9)
    at async Function.start (blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:496:125)
    at async blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:1547:22
    at async RpcChannel.receiveMessage (blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:34:36)
    at async self.onmessage (blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:1587:13)

This was after confirming that serving using the vanilla .ts example worked. I am using .js. I tried passing in the --allow-net flag myself but I'm not sure the baton got passed.

I ignored the local failure and trudged on:

mlanza@Marios-MacBook-Air df-ex % denoflare push hello-local                                     
bundling hello-local into bundle.js...
Download https://deno.land/x/postgres/mod.ts
Warning Implicitly using latest version (v0.14.2) for https://deno.land/x/postgres/mod.ts
Download https://deno.land/x/[email protected]/mod.ts
Download https://deno.land/x/[email protected]/client.ts
Download https://deno.land/x/[email protected]/client/error.ts
Download https://deno.land/x/[email protected]/connection/connection_params.ts
Download https://deno.land/x/[email protected]/pool.ts
Download https://deno.land/x/[email protected]/query/query.ts
Download https://deno.land/x/[email protected]/query/transaction.ts
Download https://deno.land/x/[email protected]/connection/message.ts
Download https://deno.land/x/[email protected]/query/decode.ts
Download https://deno.land/x/[email protected]/query/encode.ts
Download https://deno.land/x/[email protected]/utils/utils.ts
Download https://deno.land/x/[email protected]/utils/deferred.ts
Download https://deno.land/x/[email protected]/connection/connection.ts
Download https://deno.land/x/[email protected]/connection/packet.ts
Download https://deno.land/x/[email protected]/deps.ts
Download https://deno.land/x/[email protected]/query/decoders.ts
Download https://deno.land/x/[email protected]/query/oid.ts
Download https://deno.land/x/[email protected]/connection/auth.ts
Download https://deno.land/x/[email protected]/connection/message_code.ts
Download https://deno.land/x/[email protected]/connection/scram.ts
Download https://deno.land/x/[email protected]/query/array_parser.ts
Download https://deno.land/x/[email protected]/query/types.ts
Download https://deno.land/[email protected]/async/mod.ts
Download https://deno.land/[email protected]/bytes/mod.ts
Download https://deno.land/[email protected]/datetime/mod.ts
Download https://deno.land/[email protected]/encoding/base64.ts
Download https://deno.land/[email protected]/fmt/colors.ts
Download https://deno.land/[email protected]/hash/mod.ts
Download https://deno.land/[email protected]/hash/sha256.ts
Download https://deno.land/[email protected]/io/buffer.ts
Download https://deno.land/[email protected]/async/deadline.ts
Download https://deno.land/[email protected]/async/debounce.ts
Download https://deno.land/[email protected]/async/deferred.ts
Download https://deno.land/[email protected]/async/delay.ts
Download https://deno.land/[email protected]/async/mux_async_iterator.ts
Download https://deno.land/[email protected]/async/pool.ts
Download https://deno.land/[email protected]/async/tee.ts
Download https://deno.land/[email protected]/datetime/formatter.ts
Download https://deno.land/[email protected]/bytes/equals.ts
Download https://deno.land/[email protected]/bytes/bytes_list.ts
Download https://deno.land/[email protected]/io/types.d.ts
Download https://deno.land/[email protected]/hash/_wasm/hash.ts
Download https://deno.land/[email protected]/hash/hasher.ts
Download https://deno.land/[email protected]/datetime/tokenizer.ts
Download https://deno.land/[email protected]/encoding/hex.ts
Download https://deno.land/[email protected]/hash/_wasm/wasm.js
bundle finished in 1444ms
computed bindings in 0ms
putting script hello-local... (328.9kb) (93.7kb compressed)
error: Uncaught (in promise) Error: putScript failed: status=400, errors=10021 Uncaught ReferenceError: FinalizationRegistry is not defined
  at line 0

    at execute (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/common/cloudflare_api.ts:164:15)
    at async putScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/common/cloudflare_api.ts:40:13)
    at async buildAndPutScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli/cli_push.ts:52:9)
    at async push (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli/cli_push.ts:60:5)
    at async https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli/cli.ts:15:13

I tried to deploy another version of the same script using wrangler and it failed to resolve and bundle all the webpack deps. I never got it working. I got the script, same import, working on Deno Deploy in short order so I know it's conceptually sound.

I am trying to repeat that success on Cloudflare's platform using your tool. I am excited about it. Having a simple tool for bundling/deploying ES modules directly to Cloudflare will be a huge blessing. Thank you for sharing your work.

PS: I haven't crossed the TypeScript divide yet so having working JavaScript examples would be helpful for stragglers like me. I looked at the https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/common/config.schema.json and I was able to ascertain that I should use standard Worker syntax, but it took an extra couple steps to figure that out.

Denoflare using importMaps from deno.json

While I'm trying to execute my code in Denoflare, it is always complaining about my imports that have reference to the importMaps as it is recommended in Deno. Is there any config to make sure the importMaps are getting used while running denoflare?

Unable to run basic example: `Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'path')`

Hi!

I'm unable to run the basic worker example.

System information

Windows 10 Version 21H1 (OS Build 19043.1288)

➜ deno --version
deno 1.15.3 (release, x86_64-pc-windows-msvc)
v8 9.5.172.19
typescript 4.4.2

Steps to reproduce:

  1. Install denoflare:
    deno install --unstable --allow-read --allow-net --allow-env --name denoflare --force https://raw.githubusercontent.com/skymethod/denoflare/v0.3.0/cli/cli.ts

  2. Clone the denoflare repository and open a command line in the examples/hello-worker directory

  3. Run example via: denoflare serve .\hello.ts, this results in:

➜ denoflare serve .\hello.ts
error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'path')      
    const scriptPathOrUrl = scriptUrl ? scriptUrl.toString() : script!.path;
                                                                       ^
    at serve (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.0/cli/cli_serve.ts:94:72)
    at async https://raw.githubusercontent.com/skymethod/denoflare/v0.3.0/cli/cli.ts:14:13    

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.