每当刷新我的一个应用程序路由(即appname.herokuapp.com/about...
)时,我都会不断遇到以下错误。每当我刷新根appname.herokuapp.com
时,它就很好。该网站是here。
2018-10-08T06:36:36.479880+00:00 app[web.1]: TypeError: res.sendFile is not a function
2018-10-08T06:36:36.479890+00:00 app[web.1]: at app.get (/app/server.js:9:7)
2018-10-08T06:36:36.479893+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2018-10-08T06:36:36.479896+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2018-10-08T06:36:36.479897+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2018-10-08T06:36:36.479898+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2018-10-08T06:36:36.479901+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:281:22
2018-10-08T06:36:36.479902+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:354:14)
2018-10-08T06:36:36.479903+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:365:14)
2018-10-08T06:36:36.479904+00:00 app[web.1]: at Function.process_params (/app/node_modules/express/lib/router/index.js:410:3)
2018-10-08T06:36:36.479906+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/index.js:275:10)
我在论坛上四处逛逛,该错误表明我拥有的Express版本过旧,因此我检查了似乎相对最新的版本:
Running bash on ⬢ erc-hackney... up, run.2013 (Free)
1~ $ npm list express
erc-hackney@1.0.0 /app
`-- express@4.16.3
我按照此处的说明进行了设置:https://medium.com/@shubhsharma10/how-to-deploy-angular-6-app-to-heroku-52b73ac7a3aa。
server.js
的内容如下:
const express = require('express');
const http = require('http')
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, '/dist/erc-hackney/')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/erc-hackney/index.html'));
});
const port = process.env.PORT || 3000;
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log('Running...'));
package.json
的内容如下:
{
"name": "erc-hackney",
"version": "1.0.0",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"postinstall": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cli": "~6.2.4",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/compiler-cli": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"core-js": "^2.5.4",
"express": "^4.16.2",
"rxjs": "~6.2.0",
"typescript": "~2.9.2",
"videogular2": "^6.3.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.8.0",
"@angular/cli": "~6.2.4",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/core-js": "^2.5.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
}
}
我不确定发生了什么。有人可以帮忙吗?