@gregbrimble Does the separated Routes -> workers feature do the same thing functionally as well?
@gregbrimble Does the separated Routes -> workers feature do the same thing functionally as well?
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.response = await fetch()
text = await response.text()
text += '<h1>Hello</h1>'
return new Response(text)functions/index.tsfunctions/index.js <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)
}