[英]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.