Inject wixEmbedsAPI inline script into SSR responses - #36
Draft
guyofeck wants to merge 1 commit into
Draft
Conversation
Convert the single casing-normalization middleware into a sequence and add a final step that injects an inline script into every server-rendered HTML page. Running it last in the chain means it only acts once all upstream middleware has finished and the page has been rendered. The injected script defines window.wixEmbedsAPI.isWixSite, inserted just before </body> so Wix's own scripts have set up wixEmbedsAPI first. The content-length header is dropped so the runtime recomputes it for the rewritten body. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an inline script to every server-rendered HTML page that defines
window.wixEmbedsAPI.isWixSite:How
Converts the single casing-normalization middleware in
src/middleware.tsinto an Astrosequence()and adds a final step (injectWixEmbedsScript) that:next(), and fortext/htmlresponses rewrites the body to insert the script just before</body>(falling back to appending if there's no</body>).content-lengthheader so the runtime recomputes it for the rewritten body.The script is placed at the end of
<body>so Wix's own scripts have set upwindow.wixEmbedsAPIbefore the assignment runs.Verification
wix buildsucceeds.wix previewand fetched the live page — returns200 text/htmlwith the script present immediately before</body>.🤖 Generated with Claude Code