简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM