Closed Fire-Dragon-DoL closed 11 years ago
+1
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?
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
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.
The base html tag solves the issue only for html, not for ajax calls neither for css.
@Fire-Dragon-DoL Relative path is ok. You should use <img src="./logo.png" alt="Logo" />
Yes but when you start moving html files around, you'll face the issue ^^
I'll provide a protocol "app://", which refers to the root directory of the application. Will this work for you?
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.
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!
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.
@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?
@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.
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.
@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.
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 .
Oh wauw got that wrong but if that`s the case it would be awesome!
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
.
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 .
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?
Maybe you need 3 slashes app:/// the third is / path. Also, try removing the slash after index.html
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.
@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.
btw, why do you say "the relative paths are not working"? I tested it a little bit and it works here.
@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!
Version 0.7.0 was released yesterday.
The app://
protocol is now documented by @rogerwang.
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
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.