heroku上的Nodejs应用程序某些文件不加载状态H10

时间:2017-04-04 19:07:40

标签: node.js heroku

我创建了我的创业公司网站!我花了5个月。这是我的第一个Node.js Web应用程序。我在2天前完成并在Heroku上传了我的项目。开心快乐! 但我有一个很大的问题,每3或4页刷新回来的错误,consol给我状态503“name.css或name.js”服务不可用,在我的Heroku日志中我看到H10错误相同“服务不可用”。 这种情况发生在不同的文件js,css,有时图像无法加载,从不相同的文件。 我在MacBook pro上使用原子。 有谁能告诉我发生了什么事?

这是我的app.js

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var exphbs = require('express-handlebars');
var expressValidator = require('express-validator');
var session = require('express-session');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var mongo = require('mongodb');
var mongoose = require('mongoose');
var mongorelation = require('mongo-relation');
var formidable = require('formidable');
var fs = require('fs');
var device = require('express-device');
var app = express();

mongoose.connect("**************");
var db = mongoose.connection;

var routes = require('./routes/index');
var users = require('./routes/users');

app.set('views', path.join(__dirname, 'views'));
app.engine('.hbs', exphbs({
  defaultLayout:'layout',
  partialsDir: __dirname + '/views/utils/',
  extname: '.hbs',
    helpers: {
      last: function(array){return array[array.length -1].msg;},
      subject: function(str){if (str.length > 50) return str.substring(0,50) + '...'; return str; }
    }
  })
);

app.set('view engine', '.hbs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(device.capture());
app.use(express.static(path.join(__dirname, '/public')));

app.use(session({
    secret: 'secret',
    saveUninitialized: true,
    resave: true
}));

app.use(passport.initialize());
app.use(passport.session());
app.use(expressValidator({
  errorFormatter: function(param, msg, value) {
      var namespace = param.split('.')
      , root    = namespace.shift()
      , formParam = root;

    while(namespace.length) {
      formParam += '[' + namespace.shift() + ']';
    }
    return {
      param : formParam,
      msg   : msg,
      value : value
    };
  }
}));

app.use('/', routes);
app.use('/users', users);
app.set('port', (process.env.PORT || 3000));
app.listen(app.get('port'), function(){
	console.log('Server started on port '+app.get('port'));
});

这是我的package.json

{
  "name": "compname",
  "version": "1.0.0",
  "description": "compdesc",
  "private": false,
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "authors",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "*",
    "body-parser": "*",
    "connect-timeout": "^1.8.0",
    "cookie-parser": "*",
    "dotenv": "^4.0.0",
    "express": "*",
    "express-device": "^0.4.2",
    "express-handlebars": "*",
    "express-handlebars-paginate": "^1.0.3",
    "express-messages": "*",
    "express-session": "*",
    "express-validator": "*",
    "formidable": "^1.0.17",
    "handlebars-helper-eachitems": "^0.1.2",
    "handlebars-helper-paginate": "^0.2.0",
    "handlebars-paginate": "^0.1.0",
    "http": "0.0.0",
    "https": "^1.0.0",
    "image-size": "^0.5.0",
    "imagesloaded": "^4.1.1",
    "jquery": "^3.1.1",
    "masonry-layout": "^4.1.1",
    "moment": "^2.17.1",
    "mongo-relation": "^0.5.4",
    "mongodb": "*",
    "mongoose": "*",
    "mongoose-aggregate-paginate": "^1.0.5",
    "mongoose-relationship": "^0.1.5",
    "multer": "^1.2.0",
    "multer-storage-s3": "^1.1.1",
    "node-uuid": "^1.4.7",
    "nodemailer": "~0.7.1",
    "passport": "*",
    "passport-http": "*",
    "passport-local": "*",
    "promise": "^7.1.1",
    "pusher": "^1.5.1",
    "random-js": "^1.0.8",
    "s3fs": "^2.5.0",
    "socket.io": "^1.7.2",
    "twilio": "^2.11.1"
  },
  "devDependencies": {
    "handlebars-helper-paginate": "^0.2.0"
  }
}

1 个答案:

答案 0 :(得分:1)

经过一整天的苦难之后,我终于开始工作了。我将节点6.9.1的版本更新到7.8.0,将npm从3.0 ...更新到4.4.4,然后在package.json中将其更新。

{
  "name": "Fason",
  "version": "1.0.0",
  "description": "Company Name",
  "private": false,
  "main": "app.js",
  "author": "Me",
  "license": "ISC",
  "dependencies": {
    "passport-local": "*",
    "promise": "^7.1.1",
    "pusher": "^1.5.1",
    "random-js": "^1.0.8",
    "s3fs": "^2.5.0",
    "socket.io": "^1.7.2",
    "twilio": "^2.11.1"
  },
  "engines": {
        "node": "7.8.0",
        "npm": "4.4.4"
    }
}

像那样。 希望这会对某人有所帮助。