William.
03/11/2023, 7:56 PMjs
// Cloudflare middleware to append meta tags to HTML responses based on path
export async function onRequestGet(context) {
// Used to break the loop
if (context.request.url.indexOf('metatags') > -1) {
return await context.next();
}
// We're not altering any assets, so we can skip this middleware
if (context.request.url.match(/\.[a-z]/gm)) {
return await context.next();
}
// Meta tags to append to the HTML response
const metaTags = {
// Remove for brevity
};
let metas;
// Get the path from the request URL
const path = context.request.url;
if (path.indexOf('/assessment') > -1) {
metas = metaTags.assessment;
} else {
metas = metaTags.global;
}
const data = await fetch(context.request.url + '/metatags').then(function (response) {
return response.text();
})
// Append meta tags to the HTML response
let alteredHTML = data.replace('<head>', `<head>
<!--{{WORKER_META_TAGS}}-->
<title>${metas.title}</title>
<meta name="description" content="${metas.description}">
<meta name="image" content="${metas.image}">
<meta name="robots" content="${metas.noIndex ? 'noindex' : 'index'}">
<!--{{/WORKER_META_TAGS}}-->
`);
return new Response(alteredHTML, {
headers: {
'content-type': 'text/html;charset=UTF-8',
},
}, { status: 200 });
}
William.
03/11/2023, 7:56 PMWilliam.
03/11/2023, 7:58 PMfunctions
folder at the root of my angular project AND in the dist after build (tried with only root, tried with only in dist, tried with both)nightshade427
03/12/2023, 7:09 PMJames
03/12/2023, 7:15 PMnightshade427
03/12/2023, 7:48 PMJames
03/12/2023, 7:48 PMJames
03/12/2023, 7:49 PMsrc/worker
folder, with a wrangler.toml
and then run different commands for publishing to Pages/WorkersJames
03/12/2023, 7:50 PMnightshade427
03/12/2023, 7:50 PMnightshade427
03/12/2023, 7:50 PMJames
03/12/2023, 7:51 PMPetter
03/13/2023, 11:27 AMSkye
03/13/2023, 11:37 AMSkye
03/13/2023, 11:37 AMwrangler pages dev
just yetc becker
03/15/2023, 4:49 AMGreg Brimble | Cloudflare Pages
03/15/2023, 9:36 AMLarry
03/15/2023, 2:23 PMGreg Brimble | Cloudflare Pages
03/15/2023, 2:26 PMc becker
03/15/2023, 3:12 PM1ockwood
03/16/2023, 5:37 PMSkye
03/16/2023, 5:42 PM.dev.vars
file (same as a .env file), if you just mean regular env vars, you use --binding VAR_NAME=VAR_VALUE
in your pages dev
command 🙂1ockwood
03/16/2023, 5:46 PM.dev.vars
file is what I was looking for and worked perfectly. Thank you @Skye!sdev
03/18/2023, 2:06 AMHardAtWork
03/18/2023, 2:27 AMMy Account
03/18/2023, 7:12 AMMy Account
03/18/2023, 7:13 AMMy Account
03/18/2023, 7:13 AMMy Account
03/18/2023, 7:14 AMMy Account
03/18/2023, 7:14 AM