Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm built-in web server gets 404 for every css and js file included in index.html

Here is my index.html for posterity's sake:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <base href="/" />
    <title>Cart</title>
    <link href="content/external/bootstrap.css" rel="stylesheet" />
    <link href="content/external/bootstrap-theme.css" rel="stylesheet" />
    <link href="content/external/font-awesome.css" rel="stylesheet" />
    <link href="content/external/angular-toastr.css" rel="stylesheet" />
</head>
<body ng-app>

{{3+4}}

drfg



<script src="scripts/external/jquery-1.9.1.js"></script>
<script src="scripts/external/bootstrap.js"></script>
<script src="scripts/external/angular.js"></script>
<script src="scripts/external/angular-ui-router.js"></script>
<script src="scripts/external/angular-resource.js"></script>
<script src="scripts/external/angular-mocks.js"></script>
<script src="scripts/external/angular-toastr.tpls.js"></script>
<script src="scripts/external/angular-animate.js"></script>


</body>
</html>

Whenever I hit run in webstorm to open in chrome, I get a 404 for every single javascript and css file. However, if I scope to the project directory and run node's http-server, my site loads just fine. I can't seem to find anything in settings related to this. Any ideas?

like image 769
Alex Kibler Avatar asked Sep 03 '15 16:09

Alex Kibler


People also ask

Does WebStorm support HTML and CSS?

By default, WebStorm shows on-the-fly preview only for HTML and CSS code. To enable Live Edit in JavaScript, select the JavaScript, HTML and CSS option.

How do I change the web server port in IntelliJ?

To customize the parameters of the built-in web server, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Build, Execution, Deployment | Debugger. Use this spin box to specify the port on which the built-in web server runs.

How do I run a local server in IntelliJ?

Alternatively, from the main menu, select Tools | Deployment | Configuration.... and select Local or mounted folder in the popup menu. In the Create new server dialog that opens, type the name of the server to create and click OK.

How do I start an IntelliJ server live?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Build, Execution, Deployment | Debugger | Live Edit. On the Live Edit page that opens, select the Update application in Chrome on changes in checkbox. By default, IntelliJ IDEA shows on-the-fly preview only for HTML and CSS code.


1 Answers

the problem is caused by tag in index.html:

<base href="/"/>

that tells the browser to resolve all URLs in the page relative to the web server root (localhost:63342 when using built-in webserver). Obviously no resources can be found there, as the built-in webserver serves files from http://localhost:63342/<project root> So, you need to comment out '<base href="/"/>' to get your code working. Or, modify your hosts file to make webserver serve files from http://<some name>:63342 - see http://youtrack.jetbrains.com/issue/WEB-8988#comment=27-577559

like image 153
lena Avatar answered Oct 05 '22 15:10

lena