microsoft / microsoft/vscode-livepreview
Add ignore file for injected script
@andreamah is already working on this.
Since Dec 12, 2022.
- Dominant language
- TypeScript
- Stars
- 596
- Forks
- 119
- Avg merge
- 1d 4m
- Merged PRs (30d)
- 5
Description
Disclaimer: I am just getting started with web development, this might be an incredibly stupid question.
I have a small script that is using fetch() to GET some JSON data from http://localhost. For example, I will call GET /api/sensors/foo/airPressure and expect a reply like 1.653.
To emulate this with Live Preview, I have created a text file named airPressure under [project root]/api/sensors/foo/ that just contains 1.653. The problem: Live Preview will still inject its script, so the reply I am getting is something like
<script type="text/javascript" src="/___vscode_livepreview_injected_script"></script>1.653
instead of just 1.653
I am really not familiar with Typescript and extension development for VS Code - I would like to debug the extension, but I cannot. However, I am pretty sure it is this part here:
https://github.com/microsoft/vscode-livepreview/blob/c9909311c43b09780562a295661764f9a0bfdf5f/src/server/serverUtils/contentLoader.ts#L309-L315
and the according
https://github.com/microsoft/vscode-livepreview/blob/c9909311c43b09780562a295661764f9a0bfdf5f/src/utils/utils.ts#L45-L52
I understand your decision for determining a file as injectable if it has no extension, but it really isn't working in my case.
I can work around by opening the file api/sensors/foo/airPressure in VS Code and temporarily marking it as plaintext. As long as I keep the file open, the script will not be injected and Live Preview will return exactly what is on disk. But I am not sure this is a feasible solution. I could probably also give these placeholder files extensions like .txt but that would force me to change all URLs and then always change them back before it goes back into the real application.
Is there another option I'm not seeing? Would it be possible to extend the getFileStream(..) method of your content loader to act differently if the readPath is in some kind of project-wide lookup list? That could probably be a regular settings item in the extension configuration, and people like me could then add some mapping like
{
"/api/*": {
"injectable": false,
"mimeType": "application/json"
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.