You mean deploying a separate Worker?
You mean deploying a separate Worker?
functions/api/lookup.js I could request it from /api/lookup, right?functions dir handlers. _worker.js is a primarily an escape-hatch for either people with existing Workers, or framework authors.wrangler@beta aren't great, but it's beta after all. Look at @gregbrimble's stream at https://twitch.tv/gregbrimblenpx wrangler pages dev --help should give you all the options you have available /weather?functions/index.ts or functions/index.js file, and yeah, we can use HTMLRewriter for it.functions/[path].js it would act on all URLs like this:functions/[[path]].js it would act on all URLs, including these:functions/api/lookup.js/api/lookupfunctions_worker.jswrangler@betabetanpx wrangler pages dev --help/weatherfunctions/index.tsfunctions/index.jsfunctions/[path].jsfunctions/[[path]].jsresponse = await fetch()
text = await response.text()
text += '<h1>Hello</h1>'
return new Response(text) <p>
I also enjoy constructing
<a href="/crosswords">crossword puzzles</a>
.
</p>
<p>
I use
<a href="https://www.mynetdiary.com">MyNetDiary</a>
to track
<a href="/diet.html" style="color:#49D6EA !important;">what I eat</a>
.
</p>
<p id="weather">Could not load the weather</p>
</article>// ./functions/index.js
export const onRequestGet = ({ request, next }) => {
// Get the static asset response
const response = await next()
const { latitude, longitude } = request.cf
// Get weather
const weatherResponse = await fetch(`https://myweather.service/${latitude},${longitude}`)
const weatherData = await weatherResponse.json()
const { isRaining } = weatherData
// Find the placeholder in our static asset
return new HTMLRewriter().on('#weather', {
// And act on the element
element(element) {
// https://developers.cloudflare.com/workers/runtime-apis/html-rewriter#methods
element.setInnerContent(isRaining ? `It is raining 🌧` : 'It is not raining ☀️')
}
}).transform(response)
}