Isaac McFadyen | YYZ01
02/28/2022, 7:47 PM@sveltejs/adapter-cloudflare
or @sveltejs/adapter-auto
. 😄Isaac McFadyen | YYZ01
02/28/2022, 7:47 PMIsaac McFadyen | YYZ01
02/28/2022, 7:47 PMbalage
02/28/2022, 7:51 PMIsaac McFadyen | YYZ01
02/28/2022, 7:51 PMIsaac McFadyen | YYZ01
02/28/2022, 7:55 PMjavascript
export const Counter = () => {
const [state, setState] = useState(0)
return (
<div>
Counter: {state}
<button onClick={() => setState(state + 1)}>Increment</button>
<button onClick={() => setState(state - 1)}>Decrement</button>
</div>
)
}
becomes
html
<script>
let counter;
</script>
<div>
Counter: {counter}
<button on:click={() => counter += 1}>Increment</button>
<button on:click={() => counter -= 1}>Decrement</button>
</div>
balage
02/28/2022, 7:57 PMIsaac McFadyen | YYZ01
02/28/2022, 7:59 PMbalage
02/28/2022, 8:02 PMDeleted User
02/28/2022, 8:42 PMonRequestGet
function that uses an HTMLRewriter
to set the inner content of a <span class="country">
element to the country that the visitor is connecting from... but the issue is that the rewriter creates an endless loop calling itselfIsaac McFadyen | YYZ01
02/28/2022, 8:42 PMIsaac McFadyen | YYZ01
02/28/2022, 8:42 PMnext()
?Isaac McFadyen | YYZ01
02/28/2022, 8:42 PMnext
method on context
that forwards the request to the static files.Deleted User
02/28/2022, 8:42 PMts
export const onRequestGet: PagesFunction = async ({ env, request }) => {
const { cf, url } = request;
const { country } = cf;
const response = await fetch(request);
return new HTMLRewriter().on('span.country', {
element(element) { element.setInnerContent(country) }
}).transform(response);
};
This is obviously wrong, but learning here 😛Isaac McFadyen | YYZ01
02/28/2022, 8:43 PMDeleted User
02/28/2022, 8:43 PMnext
Isaac McFadyen | YYZ01
02/28/2022, 8:43 PMawait next()
where next
is an input to onRequestGet, instead of await fetch(request)
.
next()
gets the static asset that the function does proxying for.Deleted User
02/28/2022, 8:44 PMDeleted User
02/28/2022, 8:44 PMDeleted User
02/28/2022, 8:44 PMIsaac McFadyen | YYZ01
02/28/2022, 8:44 PMDeleted User
02/28/2022, 8:45 PMDeleted User
02/28/2022, 8:45 PMDeleted User
02/28/2022, 8:46 PMDeleted User
02/28/2022, 8:46 PMIsaac McFadyen | YYZ01
02/28/2022, 8:47 PMtinylobsta
02/28/2022, 9:11 PMIsaac McFadyen | YYZ01
02/28/2022, 9:11 PMtinylobsta
02/28/2022, 9:13 PMtinylobsta
02/28/2022, 9:13 PM