Under review

Redirect URLs starting with "/" to the project folder

John 4 years ago in iPad updated 4 years ago 3

Modify the server (perhaps via a checkbox) so that when previewing HTML code with root references they reflect in the project folder.

For example:

    <script src="/script.js"></script>


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:

  1. Request is made for a URL
  2. Check to see if the file exists at the request location, if it does serve the file and continue
  3. If the request is not valid (would 404), check to see if the request path starts with "/"
  4. If it does start with "/", use the "Referer" header to find the root directory of the project
  5. Serve a 302 redirect to the root directory of the project + request path

Under review

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.