lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.21k stars 85 forks source link

iframe src looking at root of webpage instead of iframe src directory (spa?) #54

Closed micsun-al closed 7 years ago

micsun-al commented 7 years ago

The set up is like the following:

localhost:8000
localhost:8000/web_page/index.html
localhost:8000/web_page/iframe/index.html
localhost:8000/web_page/iframe/scripts/some_script.js

The HTML is: <iframe src="iframe"></iframe>

I start the server using the following command line: ws --spa index.html

The error I get is: GET http://localhost:8000/iframe 404 (Not Found)

I think the expected behavior is for the relative path of the iframe src value of "iframe" to look in the subdirectory "localhost:8000/web_page/iframe" and use the spa of "index.html" as well as all the contents inside the iframe should have the relative path of the src value.

This does not seem to work with the following iframe src values:

iframe
iframe/
iframe/index.html

This does seem to work with the following iframe src values:

web_page/iframe/
/web_page/iframe/

The following partially works, but the relative path of the elements in the iframe seem to look in the parent directory, "localhost:8000/web_page", instead of "localhost:8000/web_page/iframe" (tries to serve "localhost:8000/web_page/scripts/some_script.js" instead of "localhost:8000/web_page/iframe/scripts/some_script.js").

/web_page/iframe
web_page/iframe

(Sorry if I'm doing something dumb!)

75lb commented 7 years ago

which directory are you running ws from? the web_page folder?

micsun-al commented 7 years ago

I am running ws from the parent of "web_page".

There are multiple pages I'm testing and "web_page" is one of them.

75lb commented 7 years ago

if you running this command from the parent of "web_page", it will look for the file "index.html" in the same directory.. ws serves the directory it is run from ..

Thaina commented 2 years ago

@75lb I think the default behaviour of the common static spa server is looking for nearest parent index.html of the url first. Which means with --spa command, it should serve localhost:8000/web_page/iframe with "localhost:8000/web_page/iframe/index.html"

Actually for full step, with this author's setup. given that the request is localhost:8000/web_page/iframe

  1. It should look for file web_page/iframe, if there is then serve as is
  2. If missing it should check if there is any folder web_page/iframe/ 2.1. If there is, redirect to web_page/iframe/ (add the trailing / for folder)
  3. If there is web_page/iframe/index.html then serve that file
  4. If there is web_page/index.html then serve that file
  5. If there is index.html then serve that file

Could we have this behaviour instead?

75lb commented 2 years ago

the syntax is --spa <filename>, e.g. --spa src/iframe/index.html..

you specify which html file should be served as the SPA.. does that solve your issue?

On Thu, 10 Feb 2022, 04:26 Thaina Yu, @.***> wrote:

@75lb https://github.com/75lb I think the default behaviour of the common static spa server is looking for nearest parent index.html of the url first. Which means with --spa command, it should serve localhost:8000/web_page/iframe with "localhost:8000/web_page/iframe/index.html"

Actually for full step, with this author's setup. given that the request is localhost:8000/web_page/iframe

  1. It should look for file web_page/iframe, if there is then serve as is
  2. If missing it should check if there is any folder web_page/iframe/ 2.1. If there is, redirect to web_page/iframe/ (add the trailing / for folder)
  3. If there is web_page/iframe/index.html then serve that file
  4. If there is web_page/index.html then serve that file
  5. If there is index.html then serve that file

Could we have this behaviour instead?

— Reply to this email directly, view it on GitHub https://github.com/lwsjs/local-web-server/issues/54#issuecomment-1034480348, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJQV3HU7ARHYMYK5AYGJ53U2M457ANCNFSM4CUPDLWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Thaina commented 2 years ago

you specify which html file should be served as the SPA.. does that solve your issue?

It's not. Because then when I go to localhost:8000 it then still try to serve src/iframe/index.html instead of src/index.html

As I said, common spa static server, firebase for example, will always recursively look for the spa file of the parents recursively. This behaviour let we host multiple app in each subdirectory

75lb commented 2 years ago

you can modify the spa behaviour to work in any way you like - it's just a plugin which you can fork and tweak.. see the wiki for an explanation of plugins, I'll get back to you with an example showing how to modify --spa later

On Thu, 10 Feb 2022, 05:27 Thaina Yu, @.***> wrote:

you specify which html file should be served as the SPA.. does that solve your issue?

It's not. Because then when I go to localhost:8000 it then still try to serve src/iframe/index.html instead of src/index.html

As I said, common spa static server, firebase for example, will always recursively look for the spa file of the parents recursively. This behaviour let we host multiple app in each subdirectory

— Reply to this email directly, view it on GitHub https://github.com/lwsjs/local-web-server/issues/54#issuecomment-1034507829, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJQV3C5CGQK6IEWAMRZOA3U2NEFXANCNFSM4CUPDLWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Thaina commented 2 years ago

Thank you for your explanation. Still I would like to beg for you to consider this behaviour as default of the plugin so that it not confused and could be loaded from npm

75lb commented 2 years ago

yes, that's a possibility too..

On Thu, 10 Feb 2022, 06:04 Thaina Yu, @.***> wrote:

Thank you for your explanation. Still I would like to beg for you to consider this behaviour as default of the plugin so that it not confused and could be loaded from npm

— Reply to this email directly, view it on GitHub https://github.com/lwsjs/local-web-server/issues/54#issuecomment-1034530296, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJQV3HXM4EVHMGZ4WEBLALU2NIPBANCNFSM4CUPDLWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>