forked from cloudflare/templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp workers.new/list into a workers.new/template with new design (c…
…loudflare#134) * revamp workers.list into a new design
- Loading branch information
1 parent
62445b4
commit a84595d
Showing
102 changed files
with
1,564 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
name = "workers-dot-new" | ||
compatibility_date = "2022-05-03" | ||
main = "src/index.ts" | ||
workers_dev = false |
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
examples/pages-example-forum-app/README.md → pages-example-forum-app/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Pages | ||
/.pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v16.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Cloudflare | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Image sharing platform build with Cloudflare Pages | ||
|
||
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/templates/tree/main/pages-image-sharing) | ||
|
||
This example application showcases Cloudflare Pages functions powered by Cloudflare Workers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
devServer: { | ||
hot: false, | ||
inline: false, | ||
}, | ||
style: { | ||
postcss: { | ||
plugins: [require('tailwindcss'), require('autoprefixer')], | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Download Counter Durable Object | ||
|
||
To maintain an accurate count of the number of downloads for each image, we're using Durable Objects. Each image has its own instance of the Durable Object class defined in [`./src/downloadCounter.js`](./src/downloadCounter.js). At present, wrangler v2 does not support Durable Objects, which is why this exists in its own little package. We'll update this repo when we can simplify the deployment process. | ||
|
||
## Publish | ||
|
||
```sh | ||
npm install; | ||
CF_ACCOUNT_ID="<YOUR CLOUDFLARE ACCOUNT ID>" npm run publish; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@images.page.dev/durable_objects", | ||
"version": "0.1.0", | ||
"private": true, | ||
"license": "MIT", | ||
"module": "./src/downloadCounter.mjs", | ||
"scripts": { | ||
"publish": "npx wrangler publish" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/wrangler": "^1.19.5" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
pages-image-sharing/durable_objects/src/downloadCounter.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Adapted from the example in our documentation: https://developers.cloudflare.com/workers/learning/using-durable-objects#example---counter | ||
|
||
const jsonResponse = (value, init = {}) => | ||
new Response(JSON.stringify(value), { | ||
headers: { 'Content-Type': 'application/json', ...init.headers }, | ||
...init, | ||
}); | ||
|
||
export class DownloadCounter { | ||
constructor(state) { | ||
this.state = state; | ||
// `blockConcurrencyWhile()` ensures no requests are delivered until initialization completes. | ||
this.state.blockConcurrencyWhile(async () => { | ||
let stored = await this.state.storage.get('value'); | ||
this.value = stored || 0; | ||
}); | ||
} | ||
|
||
async fetch(request) { | ||
const url = new URL(request.url); | ||
let currentValue = this.value; | ||
|
||
if (url.pathname === '/increment') { | ||
currentValue = ++this.value; | ||
await this.state.storage.put('value', currentValue); | ||
} | ||
|
||
return jsonResponse(currentValue); | ||
} | ||
} | ||
|
||
export default { | ||
fetch() { | ||
return new Response('This Worker creates the DownloadCounter Durable Object.'); | ||
}, | ||
}; |
Oops, something went wrong.