Adding Cloudflare to Demos section #6

Open
TomDo1234 wants to merge 10 commits from TomDo1234/docs.sheetjs.com:master into master
Showing only changes of commit be1192f0d3 - Show all commits

@ -113,11 +113,58 @@ free requests per day and 10 milliseconds of CPU time per invocation.
:::
1) If you do not have an account, create a new account[^7].
1) If you do not have an account, create a new Cloudflare account[^7].
### Setting up the Project and Testing
#### Setting up the Project and Testing
[The Cloudflare Docs provide a simple step by step guide to setup, develop, test, build and deploy your project](https://developers.cloudflare.com/workers/get-started/guide/)
We will be using the C3 CLI which means we do not have to interact with the Cloudflare dashboard as much.
2) Create a Worker project with C3 CLI. It will ask you to authenticate into cloudflare. It will also give you some options but for this example we will be using JS,
```bash
npm create cloudflare@latest
```
3) Install Required Dependencies
```bash
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz @aws-sdk/client-s3@3.540.0
```
4) Navigate to src/index.js, then replace the default `async fetch` function there with this
```js
const XLSX = require("xlsx");
export default {
async fetch(request, env, ctx) {
const wb = XLSX.read("S,h,e,e,t,J,S\n5,4,3,3,7,9,5", {type: "binary"});
/* write to XLSX file in a NodeJS Buffer */
const data = XLSX.write(wb, {type: "buffer", bookType: "xlsx"});
return new Response(data,{
headers: {
"Content-Disposition": 'attachment; filename="SheetJSCFWorker.xlsx"'
}
})
}
}
```
5) Start the development server
```bash
npx wrangler dev
```
Then open the browser at the port wrangler opened, it should download a file called SheetJSCFWorker.xlsx with some test data in it
6) Deploy the worker and configure live enviromnent secrets
```bash
npx wrangler deploy
```
7) Go to your Cloudflare dashboard, go to Workers & Pages, click on your worker, then go to Settings -> Triggers and then click on your worker route,
it should download SheetJSCFWorker.xlsx with the same test data
## Cloudflare R2