nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.39k stars 3.88k forks source link

/ returns to drive root path instead of app root path #363

Closed Fire-Dragon-DoL closed 11 years ago

Fire-Dragon-DoL commented 11 years ago

Sorry if I already opened this, I really don't remember and can't find it. Anyway, if I write "/" in a link, for example

<img src="/logo.png" alt="Logo" />

The image is searched (on windows for example) on path C:\logo.png. I don't know if this is a desired effect, but the biggest problem is that I have to write always relative paths in this way.

Maybe can be changed with a node.js option? I don't know, but I'm really interested because I would like to use node-webkit for a real-world application.

nprbst commented 11 years ago

+1

BenjaminDobler commented 11 years ago

I have the same issue. The problem is that i want to reuse as much code from an existing web app in node-webkit but this would only be possible if /myAsset.png would point to the location where my index.html is located and not to the filesystem root. Is there any way around this?

Fire-Dragon-DoL commented 11 years ago

I've done some researches over this. Looks like both node-webkit and phonegap have this "issue", which is not solvable without inserting a domain in /etc/hosts (linux) and run a small web server, maybe once the application started (run it with nodejs system(), after that you can just view the application from the local domain).

Otherwise, I suggest to rework the application to completely avoid the / path. Yes, it's terrible, and I would definitely prefer a solution for this.

You can use SCSS or sprockets to handle CSS paths, for tag you have the option of tag. For AJAX, string concatenation, no other solutions. :\

katanacrimson commented 11 years ago

I don't know if this is a desired effect, but the biggest problem is that I have to write always relative paths in this way.

That isn't a relative path at all, though. That is an absolute path.

Anyways, as with another thread, try the <base> html tag.

Fire-Dragon-DoL commented 11 years ago

The base html tag solves the issue only for html, not for ajax calls neither for css.

kingFighter commented 11 years ago

@Fire-Dragon-DoL Relative path is ok. You should use <img src="./logo.png" alt="Logo" />

Fire-Dragon-DoL commented 11 years ago

Yes but when you start moving html files around, you'll face the issue ^^

rogerwang commented 11 years ago

I'll provide a protocol "app://", which refers to the root directory of the application. Will this work for you?

Fire-Dragon-DoL commented 11 years ago

If the app runs from this "app://" protocol, I think it's perfect. Anyway after looking for solutions to this around the web, I understood why it's not an issue of the software (but a generic problem for this type of apps), anyway if you implement that app://, I'll love it.

BenjaminDobler commented 11 years ago

app:// sounds sweet but i`m not sure if it will help in my situation because i have a code base which i want to run ideally without modifications inside node-webkit. Also thanks to all the others for their explanations and ideas!

Fire-Dragon-DoL commented 11 years ago

Yea it won't help me too, but will be helpful, using the app:// instead of using the entire path (../) is a great addition, will speed up writing stylesheets.

rogerwang commented 11 years ago

@BenjaminDobler the 'app' protocol is designed exactly for the code reusing purpose -- if it starts from "app://" then all the '/' will refer to the root of the application directory, right?

Fire-Dragon-DoL commented 11 years ago

@rogerwang you are right and I think it's the perfect solution for this. With this, node-webkit can become the main-stream development environment for cross-platform software, at least for me, it's somewhat perfect.

buschtoens commented 11 years ago

So, just that I got it right: In the future the app will be served via the app:// protocol, making it the default protocol for all ressources, effectively making / point to the app's root path? This means that one could take an already existing website and pack it as an nw-app, without having to change it's codebase.

Fire-Dragon-DoL commented 11 years ago

@silvinci yes that's the basic idea, the / path refers to the "root of the current url" (toghether with protocol), being app:/// the root path, / will be effectively the root path for app:// protocol, solving all the issues.

buschtoens commented 11 years ago

Great! Looking forward to its implementation. :)

2013/8/2 Francesco Belladonna notifications@github.com

@silvinci https://github.com/silvinci yes that's the basic idea, the / path refers to the "root of the current url" (toghether with protocol), being app:/// the root path, / will be effectively the root path for app:// protocol, solving all the issues.

— Reply to this email directly or view it on GitHubhttps://github.com/rogerwang/node-webkit/issues/363#issuecomment-21986770 .

BenjaminDobler commented 11 years ago

Oh wauw got that wrong but if that`s the case it would be awesome!

Mithgol commented 11 years ago

Rest assured.

Even if the actual change (implied by @rogerwang) does not actually involve loading all application resources as app://whatever by default, you would still be able to get the desired behaviour if you replace {"main": "index.html"}{"main": "app://index.html"} and the rest are relative URLs that would automatically change to app://whatever.

buschtoens commented 11 years ago

Oh, that's clever!

2013/8/2 Mithgol notifications@github.com

Rest assured.

Even if the actual change (implied by @rogerwanghttps://github.com/rogerwang) does not actually involve loading all application resources as app://whatever by default, you would still be able to get the desired behaviour if you replace {"main": "index.html"} → {"main": "app://index.html"} and the rest are relative URLs that would automatically change to app://whatever.

— Reply to this email directly or view it on GitHubhttps://github.com/rogerwang/node-webkit/issues/363#issuecomment-21998408 .

BenjaminDobler commented 11 years ago

I`ve compiled the latest version eager to try it out but when i set main: app://index.html node-webkit opens like in the attached image. So index.html is not opened but instead i see the content of my app root folder. What do i miss? bildschirmfoto 2013-08-09 um 21 22 02

Fire-Dragon-DoL commented 11 years ago

Maybe you need 3 slashes app:/// the third is / path. Also, try removing the slash after index.html

BenjaminDobler commented 11 years ago

I also tried it with 3 slashes with no luck and the last slash after index.html is not set by me. In the main i just have: main: "app://index.html", The strange thing is if i write app://something/index.html it works even if something does not exists but then the relative paths are not working.

rogerwang commented 11 years ago

@BenjaminDobler the protocol is defined like http protocol: app://<host>/path. The host part is essential. You can define it to anything you want. Will document this in wiki before the release.

rogerwang commented 11 years ago

btw, why do you say "the relative paths are not working"? I tested it a little bit and it works here.

BenjaminDobler commented 11 years ago

@rogerwang thanks for clarifying! I have it now working. Think i was just confused about the host part. Thanks very much this is really nice!

Mithgol commented 11 years ago

Version 0.7.0 was released yesterday.

The app:// protocol is now documented by @rogerwang.