cloudflare / worker-sites-template Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
OR exclude it in a template exclude doc (feature of cargo-generate)
show how to setup custom caching
Ideas:
right now I am the author of everyone's stuff, and that's no bueno. base this change off of the template contribution guide.
this will be generated by wrangler
mode: development
<-- any reason for this?
This template uses the following pattern,
addEventListener('fetch', event => {
try {
event.respondWith(handleEvent(event))
} catch (e) {
...
}
})
async function handleEvent(event) { ... }
However,
event.respondWith
is required to be called in the handler without await()ing. Failing to do so yields a warning from Cloudflare (See below)handleEvent
is async, it will always return a Promise. It's not possible for the try/catch block to ever catch an error within handleEvent()
without making the event handler async and then await()ing on handleEvent
(which violates the first point).Therefore, no exceptions thrown within handleEvent
will ever be caught by this boilerplate code.
Here is a demonstrative repository: https://github.com/doublemarked/cf-workers-error-handling
Warning from Cloudflare when trying to asynchronously call event.respondWith
:
FetchEvent handler did not call respondWith() before returning, but initiated some asynchronous task. That task will be canceled and default handling will occur -- the request will be sent unmodified to your origin. Remember that you must call respondWith() before the event handler returns, if you don't want default handling. You cannot call it asynchronously later on. If you need to wait for I/O (e.g. a subrequest) before generating a Response, then call respondWith() with a Promise (for the eventual Response) as the argument.
Should throw the custom errors in release 0.0.8
Original issue cloudflare/kv-asset-handler#59
we should be v. specific about which directories should be gitignored by default. node_modules should be ignored everywhere they exist, but this isn't necessarily true for dist
and worker
.
related to cloudflare/wrangler-legacy#958
most sites don't want two responses for blah/
and blah
make sure missing the trailing slash 301s to the other
Hello,
I am not sure if this is the right place to ask this, if not please point me in the right direction. I am new to workers (and serverless in general).
I am currently trying out workers sites for some of my static sites, but a feature that I often use in NGINX is SSI, or server side includes.
I mainly do this as a basic "templating engine", so I can separate a website into header, footer, etc. files to make it easier for me to deploy changes that effect all pages without modifying all the individual pages.
I am wondering if there is any way for me to use SSI with workers sites, or if there is a branch/fork where someone has been kind enough to add support, as it would be greatly appreciated.
Thanks!
Is it possible to make it work with Serverless Framework? If so, could you please provide an example serverless.yml
to facilitate serverless deploy
?
The use case for that is to have both Workers Site and Workers in the same repo, all managed by a single serverless.yml
config and deployable via single serverless deploy
command. It is possible to have multiple Cloudflare Workers in the same repo now, but the question is whether it is possible to add Workers Site there as well.
Consider this example:
https://some-worker.workers.dev/sw.js will return 404 instead of /sw.js
Landing page should be pretty :)
Why don’t static assets like SVGs have an expire
or max-age
header?
By default we should show how the user can use the keyModifier
, specifically:
_index.html
for dirs and page.html
for pagesIn the event of a missing asset in KV (but where it is found in the manifest), we should probably just do default 404 behavior. Right now, we'll return a 500.
https://github.com/cloudflare/kv-asset-handler/blob/821dc0c45a9d750c4922c8bbece724df79dfa9b5/src/index.ts#L271 throws the error.
will then return a 500 response.Should this live over here? https://github.com/cloudflare/templates
Is there any way to get Cloudflare Apps working together with a static site deployed with Workers Sites? It seems that Apps aren't running on Workers Sites.
I have found myself typing workers-sites-template
(instead of worker-sites-template
) a few times and having it 404.
Please bump @cloudflare/kv-asset-handler to "^0.0.9" as the version in this repo has poor default caching behaviour.
As the title says, "@cloudflare/kv-asset-handler" is not up to date. Currently, it depends on "~0.0.11", which is missing the defaultMimeType
option.
we want the contents of the worker-site directory to be primarily concerned with how sites are deployed, rather than the content they deploy. the idea of a sample public directory is not necessarily bad, but it should not be adjacent to the other contents of this template; that is, index.js, package.json, and .gitignore will ultimately go into the workers-site directory, and a public directory would be placed as a sibling to that directory.
simplest impl is to just not include this directory. open to other thoughts with the caveat that leaving this will likely demand additional work on the wrangler side.
It is related to this issue. This template seems to need to stop using webpack:
cloudflare/wrangler-legacy#2108
I'm sorry about the title correction. I was on the verge of going to bed.
for our template, we should set the worker up to serve a 404.html when the response comes back without an asset.
Alright,
love wrangler and sites, but to get things on steroids, it would be amazing to deploy Jam sites created in Stackbit directly to CF.
Not sure what CloudFlare needs to do for that, but please talk to the guys at stackbit b/c getting a complete JAMstack site with a headless CMS on CF in under a minute is pretty appealing not only to me.
If this worker is deployed and nothing is returned from KV,
if (body.byteLength === 0) {
return new Response("not found", {status:404, statusText:"not found"})
}
If DEBUG
is set to false, the request that fetches the 404 page doesn' honor the options that are set above.
I have changed the following:
let notFoundResponse = await getAssetFromKV(event, {
mapRequestToAsset: req => new Request(`${new URL(req.url).origin}/404.html`, req),
})
...to this:
options.mapRequestToAsset = req =>
new Request(`${new URL(req.url).origin}/404.html`, req)
let notFoundResponse = await getAssetFromKV(event, options)
...which fixed the problem.
wrangler -V
:Generate a new site, fill your account ID into the wrangler.toml file, then run wrangler publish
without modifying anything else. This should create a site with the default Hello World template. The page has a link to workers.cloudflare.com on it.
I clicked the link and expected to go to workers.cloudflare.com
I clicked the link and went to <site-name>.<subdomain>.workers.dev/workers.cloudflare.com
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.