diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7067e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +node_modules/ +worker/ +.cargo-ok +package-lock.json +.idea +.env* +local.js +assets/pages.js +assets/partials.js +.wrangler \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..1ca15f0 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,6 @@ +# .husky/pre-commit +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +sh ./.husky/precommit.sh + diff --git a/.husky/precommit.sh b/.husky/precommit.sh new file mode 100644 index 0000000..6eb3dce --- /dev/null +++ b/.husky/precommit.sh @@ -0,0 +1,10 @@ +#!/bin/sh +FILE="./client/wrangler.toml" +if [ -f "$FILE" ]; then + sed -i -e 's/account_id = ".*"/account_id = "**********"/' $FILE + echo "$FILE updated" + git add -A +else + echo "$FILE does not exist." +fi + diff --git a/client/README.md b/client/README.md new file mode 100644 index 0000000..f220cf9 --- /dev/null +++ b/client/README.md @@ -0,0 +1,25 @@ +## Router + +This template demonstrates using the [`itty-router`](https://github.com/kwhitley/itty-router) package to add routing to your Cloudflare Workers. + +[`index.js`](https://github.com/cloudflare/worker-template-router/blob/master/index.js) is the content of the Workers script. + +#### Wrangler + +You can use [wrangler](https://github.com/cloudflare/wrangler) to generate a new Cloudflare Workers project based on this template by running the following command from your terminal: + +``` +wrangler generate myapp https://github.com/cloudflare/worker-template-router +``` + +Before publishing your code you need to edit `wrangler.toml` file and add your Cloudflare `account_id` - more information about configuring and publishing your code can be found [in the documentation](https://developers.cloudflare.com/workers/learning/getting-started#7-configure-your-project-for-deployment). + +Once you are ready, you can publish your code by running the following command: + +``` +wrangler publish +``` + +[wrangler config](https://developers.cloudflare.com/workers/wrangler/configuration/) +[handlebars](https://marnixkok.nl/news/blog/handlebars-templates-in-cloudflare-workers) +[serverless rendering](https://blog.cloudflare.com/serverless-rendering-with-cloudflare-workers) \ No newline at end of file diff --git a/client/assets/pages.js b/client/assets/pages.js new file mode 100644 index 0000000..8fb7b8e --- /dev/null +++ b/client/assets/pages.js @@ -0,0 +1,24 @@ +import Handlebars from 'handlebars/runtime.js'; + var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; +templates['body'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=container.hooks.helperMissing, alias3=container.escapeExpression, lookupProperty = container.lookupProperty || function(parent, propertyName) { + if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { + return parent[propertyName]; + } + return undefined + }; + + return "\r\n
\r\n" + + ((stack1 = container.invokePartial(lookupProperty(partials,"structure/htmlhead"),depth0,{"name":"structure/htmlhead","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + "\r\n\r\n Your name: " + + alias3(((helper = (helper = lookupProperty(helpers,"name") || (depth0 != null ? lookupProperty(depth0,"name") : depth0)) != null ? helper : alias2),(typeof helper === "function" ? helper.call(alias1,{"name":"name","hash":{},"data":data,"loc":{"start":{"line":24,"column":44},"end":{"line":24,"column":52}}}) : helper))) + + "\r\n
\r\n\r\n" + + alias3((lookupProperty(helpers,"asyncTest")||(depth0 && lookupProperty(depth0,"asyncTest"))||alias2).call(alias1,{"name":"asyncTest","hash":{"age":38,"name":"Vic Tester"},"data":data,"loc":{"start":{"line":27,"column":17},"end":{"line":27,"column":55}}})) + + "\r\n\r\n
Base64 encoding: ${base64}
+ Your name: {{name}} +
+ +{{asyncTest name='Vic Tester' age=38}}+ +