【发布时间】:2020-01-19 00:45:42
【问题描述】:
我正在尝试部署我的应用程序,但问题是在我的根文件夹中,我有两个不同的文件夹,一个用于后端,一个用于前端。 首先,我尝试按原样推送它,只是将数据库从本地更改为云端。
推送成功,但无法打开应用。得到以下错误:
应用程序发生错误,无法提供您的页面。如果您是应用程序所有者,请查看您的日志以获取详细信息。您可以在 Heroku CLI 中使用以下命令完成此操作
接下来,合并两个文件夹,并对路线进行一些必要的更改(遵循不同的教程)。现在我连推都推不动了。 尝试了很多方法,关注并查看了不同的教程、阅读指南和博客,但无法托管我的应用程序。
我的项目在 localhost 中运行良好。
这是我来自前端文件夹的package.json
{
"name": "office-space",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot -prod",
"start":"node server.js"
},
"private": true,
"dependencies": {
"@angular/cli": "~8.1.0",
"@angular/compiler-cli": "~8.1.0",
"@angular/animations": "~8.1.0",
"@angular/common": "~8.1.0",
"@angular/compiler": "~8.1.0",
"@angular/core": "~8.1.0",
"@angular/forms": "~8.1.0",
"@angular/platform-browser": "~8.1.0",
"@angular/platform-browser-dynamic": "~8.1.0",
"@angular/router": "~8.1.0",
"angular-font-awesome": "^3.1.2",
"bootstrap": "^4.3.1",
"font-awesome": "^4.7.0",
"jquery": "^3.4.1",
"material-design-icons": "^3.0.1",
"ngx-pagination": "^4.1.0",
"nonblockjs": "^1.0.8",
"pnotify": "^4.0.0",
"popper.js": "^1.15.0",
"rxjs": "~6.4.0",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.801.0",
"@angular/language-service": "~8.1.0",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/jquery": "^3.3.30",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
},
"engines": {
"node":"12.3.1",
"npm":"6.11.1"
}
}
这是我后端文件夹中的package.json
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"mongoose": "^5.6.10"
}
}
最后这是我的服务器文件
const express = require('express'),
path = require('path'),
bodyParser = require('body-parser'),
cors = require('cors'),
mongoose = require('mongoose'),
//DB = 'mongodb://localhost:27017/OfficeSpace'
DB = 'mongodb+srv://omersjd:omersjdp@officespace-szwno.mongodb.net/OfficeSpace?retryWrites=true&w=majority'
const employeeRoute = require('./routes/employee.route');
//mongoose.Promise = global.Promise;
mongoose.connect(DB, { useNewUrlParser: true }, (err, response) => {
if (err) {
console.log('Error connecting to Database: ', err)
}
else {
console.log('Connected to ' + DB);
}
});
const app = express();
app.use(express.static(__dirname + "/dist"))
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname + "/dist/OfficeSpace/index.html"))
})
app.use(bodyParser.json());
app.use(cors());
app.use('/', employeeRoute);
let port = process.env.PORT || 4000;
//console.log(employeeRoute);
const server = app.listen(port, function () {
console.log('Listening on port ' + port);
})
这是我的目录结构:
├── api (backend folder)
└── frontend-app contents
【问题讨论】:
标签: node.js angular heroku deployment