我最近尝试运行节点server.js,但由于某种原因,页面不再加载,浏览器只是无限期地等待。这是野生动物园和铬的情况。代码工作正常,页面会立即加载,但由于某种原因它现在停止工作(不确定计算机是否更新,或需要安装新版本)
如果有人能帮助弄清楚服务器无法加载的原因,我们将不胜感激。
我的server.js文件如下:
var express = require('express');
var fundsapp = require('./fundsapp.js');
var app = express();
app.use('/js', express.static(__dirname + '/public/js'));
app.use('/libs', express.static(__dirname + '/public/libs'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/views', express.static(__dirname + '/public/views'));
// app.use('/public/partials', express.static(__dirname + '/public/partials'));
// app.use('/public/js/controllers', express.static(__dirname + '/public/js/controllers'));
// app.use('/public/services', express.static(__dirname + '/public/js/services'))
app.get('/:cik/:startdate/:enddate/:startingtotal', function (req,res) {
// console.log(fundsapp.absolutedollarvalue(req.params.cik, req.params.startdate, req.params.enddate, req.params.startingtotal))
})
app.get('/api/returns', function(req,res) {
console.log(req.query)
fundsapp.calculateReturns(req.query.startDate, req.query.endDate, res, req.query.cik, req.query.benchmark)
})
app.get('/api/adv', function(req,res) {
console.log(req.query)
fundsapp.absolutedollarvalue(req.query.startDate, req.query.endDate, req.query.cik, req.query.startingAmount, res)
})
//app.get('*', function(req, res) {
// res.sendfile('./public/index.html');
app.get('/', function(req, res) {
res.sendFile('public/index.html' , { root : __dirname});
});
app.listen(8080, function() {
console.log("Listening on port 8080")
})
我的index.html文件如下:
<!-- public/index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="/">
<title>Home</title>
<!-- CSS -->
<!-- <link rel="stylesheet" href="libs/bootstrap/dist/css/bootstrap.min.css"> -->
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="libs/angular-bootstrap/ui-bootstrap-csp.css">
<link rel="stylesheet" href="css/style.css"> <!-- custom styles -->
<link rel="stylesheet" href="libs/angular-chart.js/dist/angular-chart.css">
<link rel="stylesheet" href="libs/angular-ui-grid/ui-grid.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.4/angular-material.css">
<!-- JS -->
<script src="libs/angular/angular.min.js"></script>
<script src="libs/angular-route/angular-route.min.js"></script>
<script src="libs/Chart.js/Chart.js"></script>
<script src="libs/angular-chart.js/dist/angular-chart.min.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
<script src="libs/angular-ui-grid/ui-grid.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-aria.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.4/angular-material.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-messages.min.js"></script>
<!-- ANGULAR CUSTOM -->
<script src="js/controllers/MainCtrl.js"></script>
<script src="js/controllers/TestCtrl.js"></script>
<script src="js/controllers/AdvCtrl.js"></script>
<script src="js/controllers/ReturnsCtrl.js"></script>
<script src="js/appRoutes.js"></script>
<script src="js/app.js"></script>
<script src="js/config.js"></script>
</head>
<body ng-app="alphaApp" ng-controller="TestController">
<div class="container">
<!-- HEADER -->
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="/">Home</a>
</div>
<!-- LINK TO OUR PAGES. ANGULAR HANDLES THE ROUTING HERE -->
<ul class="nav navbar-nav">
<li><a href="/returns">Returns</a></li>
<li><a href="/adv">Absolute Returns</a></li>
</ul>
</nav>
<!-- ANGULAR DYNAMIC CONTENT -->
<div ng-view></div>
</div>
</body>
</html>
如果有任何其他信息有用,请告诉我们。我很困惑,为什么突然间它停止加载。我尝试卸载并重新安装node,npm,express和bower无济于事。
感谢您的帮助!
编辑: 它看起来像是从index.html文件中尝试访问我不再在文件夹中看到的libs文件夹。有没有一种简单的方法来安装充满角度文件的libs文件夹?
答案 0 :(得分:0)
尝试将端口号更改为5000或5050之类的任何其他端口,因为您可能正在运行任何其他使用该端口的应用程序。
app.listen(5000, function() {
console.log("Listening on port 5000")
})
答案 1 :(得分:0)
对于那些似乎不存在的文件,您好像在这里引用libs
文件夹:
<script src="libs/angular/angular.min.js"></script> <script src="libs/angular-route/angular-route.min.js"></script> <script src="libs/Chart.js/Chart.js"></script>
为什么不将这些行更改为供应商js文件所在的位置?