3

I am running a project where all the relative links work fine when I launch an index.html file from app/index.html. The URL is like: http://localhost:63342/projectName/app/index.html structure:

projectName/
    app/
    rel/

however after I added rel as a content root, still links starting with a / (pointing to a web root) are broken when it tries launch it in

http://localhost:63342/rel/foo.html

<link rel="stylesheet" href="/rel/foo.html" />

I've tried setting mysite as content root but still have the same issue. In fact WS highlights those links starting with / as unresolvable.

2
  • Is it http://localhost:63342/projectName/rel/ or http://localhost:63342/rel/ ? I see you referencing both there, and they are not the same. Aug 26, 2014 at 21:39
  • @DarthAndroid localhost:63342/rel when url starts only with /
    – Nikos
    Aug 26, 2014 at 22:10

2 Answers 2

2

The only "workaround" I'm aware of in order to use WebStorm's Built-in Server with absolute URLs is to edit your /etc/hosts file (on Mac/Linux) or C:\Windows\System32\drivers\etc\hosts file (on Windows). In your case, you would change the line 127.0.0.1 localhost to 127.0.0.1 ProjectName. Then, you would set a custom port for the Built-in Server by going to Settings -> Debugger -> JavaScript -> Built-in server port 8090 (on older versions of WebStorm) or by going to Settings -> Build, Execution, Deployment -> Debugger -> Built-in server port 8090 (on newer versions of WebStorm). Once you've done this, you should be able to go to http://projectName:8090 and absolute URLs should work.

But as lena suggested, I would opt in for a local web server setup (Apache, MAMP, WAMP, etc) to host your web project since WebStorm's Built-in Server is very basic and doesn't address this use case.

I got this information by visiting http://blog.jetbrains.com/webstorm/2013/03/built-in-server-in-webstorm-6/ and looking at the comment by Vladimir Krivosheev on July 2, 2013 at 6:52 am.

0

Hmm... I'm not sure what is expected here... Links that start with slash are resolved relative to the web server root (http://localhost:63342 in your case). And obviously http://localhost:63342/rel/foo.html results in 404 as there is no such path on your server... You can change it to href="/projectName/foo.html" to make it work

2
  • is there a way to get webstorm to add a directory as a web server root when running its own internal server? I tried marking a directory as resource root but that doesn't do what I need. of course in dev our files are in the correct location after a build process but locally its not the case.
    – Nikos
    Oct 17, 2014 at 9:41
  • If you like to change the default web path on built-in web server, you have to re-configure the server by editing your system hosts file accordingly - see youtrack.jetbrains.com/issue/WEB-8988#comment=27-577559. Or, just use a 'normal' web server (Apache, etc.) to host your files and configure it in the way you like
    – lena
    Oct 17, 2014 at 13:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .