#simplest static asset hosting

19 messages · Page 1 of 1 (latest)

gloomy granite
#

So, I read through https://github.com/cloudflare/workers-sdk/issues/1162 and it was closed due to the wrangler deploy --assets flag existing; do we have any actual documentation about how that works? Can it be used to host assets for a worker or is it just for using a worker to only host static assets?

I'm curious about that answer regardless of whether this is actually the right solution (this is phrased an intentional XY problem), but backing up to give the context as well: I'm hosting discord bots on Workers and am trying to figure out the simplest way (to make a minimal template) to include more than 1MB of assets that they can access (the 25MB/file KV limit is fine here; would attach R2 for anything larger, I get that part). That I can tell, the methods that let you just have a directory in your repo whose contents are autodeployed are:

  • Use @cloudflare/kv-asset-handler as per https://developers.cloudflare.com/workers/configuration/sites/start-from-worker/. Works, boilerplate-y.
  • Actually deploy a pages site with one function instead of a worker; have the worker fetch a relative path. Works, feels kind of silly?
  • Deploy your folder of static assets as a separate static pages site and fetch that site from your worker, hardcoding the .pages.dev domain (I actually did this one because I was lazy and I knew it would work).
  • Something else? Is that what the --assets flag does? What's this I hear about an ASSETS binding; is that only for pages?
livid thistle
#

If you can deploy it as a Function, then you shouldn't need the Worker

gloomy granite
#

Well, the application is just a Discord bot. Deploying it as a Function would be my second bullet point option, yeah? Using the Pages stack despite not having a site to actually deploy?

livid thistle
gloomy granite
#

I don't have the version of it with assets public yet; got to strip some secrets and stuff

#

But to have a bot command respond with an image, I'm currently just fetching my-static-files.pages.dev/some-image.png

#

(and made a separate repo that's just a folder of images and uploaded that as a pages site)

livid thistle
gloomy granite
#

Is there a nice way to have a folder in the repo synced to R2 (e.g. from wrangler cli)?

livid thistle
#

I should note too that while you can do as you are doing it now, using Pages as a static file locker, rather than a website hosting platform, is technically against the ToS

gloomy granite
livid thistle
gloomy granite
#

Right, yeah, the linked issue seemed to be well-targeted toward finding a solution to just this sort of thing with good devx, and then it wasn't clear to be if the resolution it was closed with actually does that

gloomy granite
gloomy granite
#

Will look through that. But I meant more, backing up, that the user would have to be instructed to make an R2 binding and add it to one or multiple config files as part of using the template to make a bot, yeah? While the bucket = "./public" method is zero config, as one would reasonably expect