-
-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(edge): Inject JS code into 3rd party landing pages (#383)
- Loading branch information
Showing
11 changed files
with
159 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ | |
# Misc | ||
/.husky | ||
*.hbs | ||
*.ejs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* SPDX-FileCopyrightText: 2014-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
import { getCookie } from "hono/cookie"; | ||
import { app } from "../core/app"; | ||
import snippet from "../views/landing.ejs"; | ||
|
||
// Serve landing pages | ||
app.use("*", async (ctx, next) => { | ||
const url = new URL(ctx.req.url); | ||
|
||
if (!["/", "/about", "/home"].includes(url.pathname)) { | ||
return next(); | ||
} | ||
|
||
// Indicates whether the user was previously authenticated | ||
const isAuthenticated = getCookie(ctx, "auth") === "1"; | ||
|
||
// Do not serve the home landing page to authenticated users | ||
if (url.pathname === "/" && isAuthenticated) { | ||
return next(); | ||
} | ||
|
||
const res = await fetch("https://example.framer.app/", ctx.req.raw); | ||
|
||
return new HTMLRewriter() | ||
.on("link", { | ||
element(el) { | ||
if (el.getAttribute("rel") === "icon") { | ||
el.setAttribute("href", "/favicon.ico"); | ||
} | ||
}, | ||
}) | ||
.on("body", { | ||
element(el) { | ||
el.onEndTag((tag) => { | ||
try { | ||
tag.before(snippet(ctx.env), { html: true }); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
}, | ||
}) | ||
.transform(res.clone()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script type="module"> | ||
import { initializeApp, getApp } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-app.js"; | ||
import { getAuth } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-auth.js"; | ||
const app = initializeApp({ | ||
projectId: "<%- env.GOOGLE_CLOUD_PROJECT %>", | ||
appId: "<%- env.FIREBASE_APP_ID %>", | ||
apiKey: "<%- env.FIREBASE_API_KEY %>", | ||
authDomain: "<%- env.FIREBASE_AUTH_DOMAIN %>", | ||
}); | ||
const auth = getAuth(app); | ||
auth.onAuthStateChanged((user) => { | ||
if (user) { | ||
console.log("User is signed in"); | ||
} else { | ||
console.log("User is signed out"); | ||
} | ||
}); | ||
</script> | ||
|
||
<script async src="https://www.googletagmanager.com/gtag/js?id=<%- env.GA_MEASUREMENT_ID %>"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { | ||
dataLayer.push(arguments); | ||
} | ||
gtag("js", new Date()); | ||
gtag("config", "<%- env.GA_MEASUREMENT_ID %>"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters