diff --git a/.husky/precommit.sh b/.husky/precommit.sh index 996cf3e..9f3ba26 100644 --- a/.husky/precommit.sh +++ b/.husky/precommit.sh @@ -3,6 +3,7 @@ FILE="./client/wrangler.toml" if [ -f "$FILE" ]; then cp $FILE ~/tmp.wrangler.toml sed -i -e 's/account_id = ".*"/account_id = "**********"/' $FILE + sed -i -e 's/pattern = ".*"/pattern = "**********"/' $FILE echo "$FILE updated" git add -A else diff --git a/README.md b/README.md new file mode 100644 index 0000000..1d47315 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Serverless Microapp + +## Client Hosted on Cloudflare Workers +- uses itty-router for Express-like routing +- uses handlebars for views engine +- 100,000 free requests per day + +## Server Hosted on AWS Lambda +- uses node engine +- best for database operations (i.e. working with MongoDB) diff --git a/client/README.md b/client/README.md index f220cf9..de00d80 100644 --- a/client/README.md +++ b/client/README.md @@ -20,6 +20,6 @@ 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 +- [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..4e9db74 --- /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 Cloudflare Workers with Handlebars\r\n\r\n\r\n\r\n" + + ((stack1 = container.invokePartial(lookupProperty(partials,"structure/header"),depth0,{"name":"structure/header","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + "\r\n
\r\n
\r\n
\r\n\r\n
\r\n
\r\n" + + ((stack1 = container.invokePartial(lookupProperty(partials,"logos/cloudflare"),depth0,{"name":"logos/cloudflare","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + "
\r\n
\r\n\r\n

This template is rendered by Handlebars in a Cloudflare Worker!

\r\n\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":{"name":"Vic Tester"},"data":data,"loc":{"start":{"line":27,"column":17},"end":{"line":27,"column":48}}}))
+    + "
\r\n\r\n
\r\n
\r\n
\r\n\r\n" + + ((stack1 = container.invokePartial(lookupProperty(partials,"structure/footer"),depth0,{"name":"structure/footer","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + "\r\n"; +},"usePartial":true,"useData":true}); diff --git a/client/assets/partials.js b/client/assets/partials.js new file mode 100644 index 0000000..e3a239e --- /dev/null +++ b/client/assets/partials.js @@ -0,0 +1,20 @@ +import Handlebars from 'handlebars/runtime.js'; + var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; +Handlebars.partials['logos/cloudflare'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return "\r\n\r\n \r\n \r\n \r\n Cloudflare logo\r\n \r\n \r\n \r\n \r\n"; +},"useData":true}); +Handlebars.partials['logos/handlebars'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return ""; +},"useData":true}); +Handlebars.partials['structure/footer'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return ""; +},"useData":true}); +Handlebars.partials['structure/footerlibs'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return ""; +},"useData":true}); +Handlebars.partials['structure/header'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return "\r\n
"; +},"useData":true}); +Handlebars.partials['structure/htmlhead'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return "\r\n\r\n"; +},"useData":true}); diff --git a/client/wrangler.toml b/client/wrangler.toml index 1724e7e..52d77b7 100644 --- a/client/wrangler.toml +++ b/client/wrangler.toml @@ -3,6 +3,10 @@ account_id = "**********" workers_dev = true compatibility_date = "2024-07-11" +[route] +pattern = "**********" +custom_domain = true + [build] command="npm run build" watch_dir="views/" \ No newline at end of file