Redirect URLs starting with "/" to the project folder
Modify the server (perhaps via a checkbox) so that when previewing HTML code with root references they reflect in the project folder.
For example:
<head>
<script src="/script.js"></script>
</head>
would have "/script.js" redirected to "localhost/XYZ/Root project folder/script.js" via a 302 request, and maybe an option to toggle this?
You can use the "Referer" request header to assosiate the request to a project, and then alter the URL accordingly.
In your past comments on the issue you added to 'just use <script src="script.js"></script> instead' which doesn't work when you have a nested file structure such as:
Project Root
-> script.js
-> index.html
-> Nested Folder
----> page_1.html
-> Images
----> image_1.png
And you want page_1.html to access images or scripts from the root. (i.e. an image with the path "/Images/image_1.png" is the correct way of doing this).
The current behaviour (of not redirecting) makes serious "nested folder" (as in the majority of websites) web development near-impossible on the editor, as you can't locally test.
To confirm the steps for a fix:
- Request is made for a URL
- Check to see if the file exists at the request location, if it does serve the file and continue
- If the request is not valid (would 404), check to see if the request path starts with "/"
- If it does start with "/", use the "Referer" header to find the root directory of the project
- Serve a 302 redirect to the root directory of the project + request path
Customer support service by UserEcho
Thanks for the detailed suggestion.
Just a quick note: in page_1.html in the nested folder you can actually access the image from the Images subfolder of the root: just use "../Images/image_1.png" as the path.
Here's a problem with the referrer approach you suggested:
When previewing the file "Project Root/Nested Folder/page_1.html", how is the server supposed to know that the project root is "Project Root" and not "Project Root/Nested Folder"? The referrer header in that case is "Project Root/Nested Folder/page_1.html", so that doesn't work.