我试图在heroku上部署我的node.js应用,但是在heroku链接上却出现错误:
Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.
在Heroku日志中,出现以下错误:
fa61d-e6e6-4411-82a8-fe1153fba21f fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:41:21.728628+00:00 heroku[run.4857]: State changed from starting to up
2018-06-28T14:41:21.759085+00:00 heroku[run.4857]: Awaiting client
2018-06-28T14:41:21.816432+00:00 heroku[run.4857]: Starting process with command `rails console`
2018-06-28T14:41:26.823049+00:00 heroku[run.4857]: Process exited with status 127
2018-06-28T14:41:26.838513+00:00 heroku[run.4857]: State changed from up to complete
2018-06-28T14:42:20.738584+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=backendnodednz.herokuapp.com request_id=50d4ace8-b249-477e-ae84-d8d7ccb98193 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:42:21.055492+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=backendnodednz.herokuapp.com request_id=0fcef98f-7c95-49be-b0b4-ac1450cd43e0 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:44:02.574983+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=backendnodednz.herokuapp.com request_id=9bbc65e4-6d1a-475d-b9a3-6833a47572eb fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:44:02.893640+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=backendnodednz.herokuapp.com request_id=b4d92917-7e46-4a41-aec5-d9c960f6a5ee fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:46:48.276037+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=backendnodednz.herokuapp.com request_id=04d29fd8-773a-425e-ac8c-1600f3df6cb0 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:46:48.676614+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=backendnodednz.herokuapp.com request_id=d4521abd-4924-48ca-94f1-7b794b29138e fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:46:59.664436+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=backendnodednz.herokuapp.com request_id=99187788-a5da-42af-a36c-49e7683b1e09 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:47:00.036274+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=backendnodednz.herokuapp.com request_id=f78584a9-f084-417f-b80e-ed8b812242c1 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:48:28.888549+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=backendnodednz.herokuapp.com request_id=a6caa1e9-50ad-46b6-b11c-95c621d1b225 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:48:29.289569+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=backendnodednz.herokuapp.com request_id=2080ac44-d4e7-47e4-91da-67df7ca049f5 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:48:44.421127+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=backendnodednz.herokuapp.com request_id=8404bfc6-7417-4e88-9b59-d26c222a2e85 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:48:44.746489+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=backendnodednz.herokuapp.com request_id=3b125047-8588-4cb2-9be3-102527295c8b fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:49:25.930715+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=backendnodednz.herokuapp.com request_id=5dcf8f1d-fb84-4a75-b4a1-36d1a8a9ee59 fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
2018-06-28T14:49:26.302012+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=backendnodednz.herokuapp.com request_id=bd3a603e-256c-4538-be63-867471edba8d fwd="62.96.178.212" dyno= connect= service= status=503 bytes= protocol=https
是否可以对我的节点app.js端口进行某些处理?或者也许与当地的mongodb?我还使用了有效的mlab mongodb url,它可以很好地连接,但并没有帮助... 我在Node中的app.js是这样的:
var express = require('express');
//const expressOasGenerator = require('express-oas-generator');
var app = express();
//expressOasGenerator.init(app, {});
var bodyParser = require("body-parser");
var morgan = require("morgan");
var routes = require('./routes');
var cors = require('cors');
var swaggerUi = require('swagger-ui-express'),
swaggerDocument = require('./swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
//configure app
app.use(morgan('dev')); //log requests to the console
app.use(cors());
//configure body parser
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
var options = {
inflate: true,
limit: '100kb',
type: 'application/*'
};
var rawParser = bodyParser.raw(options);
//app.use(rawParser);
// parse an HTML body into a string
var textParser= bodyParser.text({ type: 'text/plain' });
//app.use(textParser);
var port = process.env.PORT || 5000;
//DATABASE SETUP
var mongoose = require('mongoose');
//mongoose.Promise = global.Promise;
url2 = 'mongodb://localhost/DNZ';
mongoose.connect(url2);
//.then(function(){
// console.log(" Connected to dbName ".green);
// }).catch(err => console.error(err));; //connect to our datbaase
//Handle the connection event, get reference to database.
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("DB connection alive");
});
//ROUTES FOR OUR API
//=============================================================================
//create our router
var router = express.Router();
//middleware to use for all requests
router.use(function(req, res, next) {
// do logging
console.log('Something is happening.');
//console.log('Today is:', Date())
next();
});
//test route to make sure everything is working (accessed at GET http://localhost:5000/DNZ/)
router.get('/', function(req, res) {
res.json({ message: 'Welcome to DNZ API!' });
});
////////////////////////////////////////////////////////////////
/*
//REGISTER OUR ROUTES -------------------------------
app.use('/Test', router);
//START THE SERVER
//=============================================================================
// set static directories
app.use(express.static('./dist'));
app.use(cors());
// Define Routes
var index = require('./routes/index');
var users = require('./routes/users');
//Set up routes
routes.init(app)
//run
app.listen(port);
console.log('Server started, Listening on port ', port);