Add static content to localhost

If I create a new web project in WebStorm and hit run I get a localhost:<port>/<project> URL.

Is there a way to add static content to the localhost server as it would be out on the live server?  I have a public directory that holds static content that is shared amongst all my sites.  I use relative paths so that way as my code moves through Integration, QA, to PROD it always works.

Any ideas?

4 comments
Comment actions Permalink

Not sure I follow you... Do you mean changing built-in web server URL from 'localhost:63342/project_name' to just 'localhost:port'?
You can't change the doc root to have the pages accessible as

http://localhost:port/index.html
, but you can try changing hosts file to make them accessible as
http://<project_name>:63342/index.html
, where <project_name> is a name set in hosts file, like '127.0.0.1 <specified_name>', as it's written in https://youtrack.jetbrains.com/issue/WEB-8988#comment=27-577559
0
Comment actions Permalink

Elena,
No, I am looking for a way to add a directory that has static content, to the server, so my project can access it.

Example

Directory (external to the project)
/public/css/main.css

And I have a project with a webpage that uses that main.css  /webstorm workspace/test/index.html, but reference it by relative path to the server

 
<link href="/public/css/main.css" rel="stylesheet">
  
I click run in Webstorm and http://localhost:63342/test/index.html comes up, obviously the server doesn't know about /public/css/main.css
  
Is there a way to configure the server to add that directory as part of the server?
  
I hope that makes sense.
0
Comment actions Permalink

Well ... you can always add any external folder as Additional Content Root (Settings | Project | Directories) so it will become part of the project ... but that will not help with URL as (as described above by Elena) the URL for such resource will still include project name in it (e.g. /test/public/css/main.css)

Although you may try marking that folder as a Resource Root -- may help (not so sure though)

0
Comment actions Permalink

Thanks.  I will give that a try.  That is what I was looking for to be able to add a directory.

0

Please sign in to leave a comment.