Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update injectCode.ts to append code when closing tags not detected #154

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/middleware/injectCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class Inject extends Writable {

if (this.injectTag) {
data = data.replace(this.injectTag, this.code + this.injectTag)
} else {
data = data + '\n' + this.code
Comment on lines +51 to +52
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fall back to appending the injection script if no closing tag is found.

}

// convert cache to [src|href]="/.cache/.."
Expand Down Expand Up @@ -113,12 +115,9 @@ export const injectCode = (root: string, baseURL: string, PHP: any, injectBodyOp
createReadStream(filePath)
.pipe(inject)
.on('finish', () => {
if (!inject.injectTag) return next()
else {
res.type('html')
res.setHeader('Content-Length', inject.data.length)
res.send(inject.data)
}
res.type('html')
res.setHeader('Content-Length', inject.data.length)
res.send(inject.data)
Comment on lines -116 to +120
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional check here is removed because now the injection always happens, regardless if a closing tag was found or not.

})
.on('error', () => {
return next()
Expand Down