![](/img/trans.png)
[英]Why am I getting a "Cannot GET /error" message when running my app?
[英]I cannot get my Angular app running locally
我无法让我的角度应用程序在本地运行。 我收到一个错误,未找到我的visitview.js和angular.js。 另外,当我从开发者控制台中打开angular。时,未在views.js文件中定义它。
这是我的目录结构:
mock
public
index.html
src
services
interview.js
vendor
angular.js
这是我的index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Interview Practice</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="../vendor/angular.js" type="text/javascript"></script>
</head>
<body ng-app="interviewapp">
hello world!
<script src="../src/interview.js" type="text/javascript"></script>
</body>
</html>
这是我的访谈.js
angular.module("interviewapp", []);
console.log("does this work");
我正在使用http服务器启动应用程序。
Starting up http-server, serving ./public
Available on:
http://10.66.87.184:8080
http://192.168.56.1:8080
http://127.0.0.1:8080
进入localhost或那里列出的任何https,这是我得到的错误:
http://10.66.87.184:8080/vendor/angular.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://10.66.87.184:8080/src/interview.js Failed to load resource: the server responded with a status of 404 (Not Found)
如何解决此问题,以便我的应用程序运行?
如评论中所述:
将src
和vendor
目录移到public
目录,然后从路径开头删除..文件,例如,将src="../src/interview.js"
更改为src="/src/interview.js"
之所以可行,是因为您的服务器使用public
作为根文件夹,因此它无法看到您尝试访问的其他文件夹。 通过在移动他们public
文件夹,它就可以访问它们。
更改您的项目结构,如下所示:
mock
public
index.html
src
vendor
也改变这个:
<script src="../vendor/angular.js" type="text/javascript"></script>
对此:
<script src="/vendor/angular.js" type="text/javascript"></script>
和这个:
<script src="../src/interview.js" type="text/javascript"></script>
对此
<script src="/src/interview.js" type="text/javascript"></script>
因此,所有JavaScript都应位于您的公共目录中。 也不要将相对路径用于include标签。 公共目录中的任何内容都应可访问,因为它是根文件夹。
你的服务器在为public
文件夹。 因此,可以通过您的主机名访问该文件夹中的任何内容。 但是,您已将src
和vendor
public
,因此不会通过您的服务器提供服务。 为了访问它们,请将它们放在public
文件夹中,并在您的js引用之前删除..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.