Javascript 从节点服务器提供角度生成输出时出错
我在名为Javascript 从节点服务器提供角度生成输出时出错,javascript,node.js,angular,Javascript,Node.js,Angular,我在名为angular app的文件夹中创建了一个angular app,并使用ng build成功创建了一个构建。我使用http服务器测试了构建。我导航到angular app文件夹并运行 http服务器/dist 然后渲染角度应用程序。这是构建的angular-app/dist/index.html页面 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> &l
angular app
的文件夹中创建了一个angular app,并使用ng build
成功创建了一个构建。我使用http服务器测试了构建。我导航到angular app
文件夹并运行
http服务器/dist
然后渲染角度应用程序。这是构建的angular-app/dist/index.html
页面
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AngularApp</title>
<base href="/angular-app/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="runtime.js"></script><script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="styles.js"></script><script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="main.js"></script></body>
</html>
现在运行节点服务器,我希望节点服务器在加载http://localhost:3000//angular
。
但我在浏览器控制台中给出了以下错误
GET http://localhost:3000/angular/angular-app/runtime.js 404 (Not Found)
Refused to execute script from '<URL>' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
angular:13 GET http://localhost:3000/angular/angular-app/polyfills.js 404 (Not Found)
favicon.ico:1 GET http://localhost:3000/angular/angular-app/favicon.ico 404 (Not Found)
GEThttp://localhost:3000/angular/angular-app/runtime.js 404(未找到)
拒绝从“”执行脚本,因为其MIME类型('text/html')不可执行,并且启用了严格的MIME类型检查。
角度:13分http://localhost:3000/angular/angular-app/polyfills.js 404(未找到)
法维康。ico:1得到http://localhost:3000/angular/angular-app/favicon.ico 404(未找到)
有没有想过我错过了什么
更新:根据注释将app.get('/angular')更改为app.get('*'),但控制台中仍然出现以下错误
Uncaught SyntaxError: Unexpected token <
polyfills.js:1 Uncaught SyntaxError: Unexpected token <
styles.js:1 Uncaught SyntaxError: Unexpected token <
vendor.js:1 Uncaught SyntaxError: Unexpected token <
main.js:1 Uncaught SyntaxError: Unexpected token <
未捕获的语法错误:意外标记<
polyfills.js:1未捕获的语法错误:意外标记<
styles.js:1未捕获的语法错误:意外标记<
vendor.js:1未捕获的语法错误:意外标记<
main.js:1未捕获的语法错误:意外标记<
您的服务器不提供类似http://localhost:3000/angular/angular-app/polyfills.js
-您需要将所有文件请求重定向到dist/
-当前您只将一个-/angular
重定向到/dist/index.html
在这里,您可以获得有关如何执行此操作的更多信息:尝试将
更改为
已尝试,但仍然存在相同的错误您的服务器无法提供类似的文件http://localhost:3000/angular/angular-app/polyfills.js
-您需要将所有文件请求重定向到dist/
-当前您只重定向到一个-/code>/地区/索引。html@KamilKiełczewski按照建议进行了尝试,但在控制台中出现了新的错误。用新错误更新了问题。看一看可能会有帮助:有没有办法定义一个特定的路线来显示Angular应用程序而不是*?
Uncaught SyntaxError: Unexpected token <
polyfills.js:1 Uncaught SyntaxError: Unexpected token <
styles.js:1 Uncaught SyntaxError: Unexpected token <
vendor.js:1 Uncaught SyntaxError: Unexpected token <
main.js:1 Uncaught SyntaxError: Unexpected token <