Javascript Angularjs,表示来自不正确静态路由的无限循环,但随后是MIME类型text/html

Javascript Angularjs,表示来自不正确静态路由的无限循环,但随后是MIME类型text/html,javascript,angularjs,node.js,html,express,Javascript,Angularjs,Node.js,Html,Express,这个问题是一个完整的循环,而不仅仅是无限循环。我使用的是AngularjsHTML5模式,以及Express catch all route/*。当我请求一个页面时,一个无限循环开始,因为Express找不到静态资产路由,它触发了catch-all路由,该路由被提供给客户端。这会重复,因为我正在发送index.html 这是问题的第一部分,它存在于以下代码中: 快速应用程序: // Serve static files app.use('/static', express.static(conf

这个问题是一个完整的循环,而不仅仅是无限循环。我使用的是Angularjs
HTML5模式
,以及Express catch all route
/*
。当我请求一个页面时,一个无限循环开始,因为Express找不到静态资产路由,它触发了catch-all路由,该路由被提供给客户端。这会重复,因为我正在发送index.html

这是问题的第一部分,它存在于以下代码中:

快速应用程序:

// Serve static files
app.use('/static', express.static(config.PUBLIC));

/* ...
   ... define app routes
   ...
*/ 

// catch all route
app.use('/*', function(req, res) {
    res.sendFile(config.PUBLIC + "index.html");
});
index.html:

<html ng-app="myapp">
<head>
    <base href="/"></base>
    <link rel="stylesheet" href="/static/css/custom.css">
</head>
<body>
    <!-- main html body code -->

    <script src="/static/js/app.js"></script>
    <script src="/static/js/other.js"></script>
</body>
</html>
最终,您会得到一个错误,上面写着:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
为了解决这个问题,我在Express
/static
路线中添加了一个通配符:

app.use('/static/*', express.static(config.PUBLIC));
这是因为它触发的是静态路由,而不是全面捕获路由。但是,浏览器现在会导致一系列错误:

Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:1234/static/js/app.js/".

Uncaught SyntaxError: Unexpected token <
资源解释为脚本,但使用MIME类型text/html传输:http://localhost:1234/static/js/app.js/".
未捕获的语法错误:意外标记<
。。。等等

现在我被难倒了。如何提供静态文件

Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:1234/static/js/app.js/".

Uncaught SyntaxError: Unexpected token <