mardi 3 mars 2015

502 Bad Gateway NodeJS/MongoDB AWS Elastic Beantstalk

I am running into a 502 Bad Gateway issue trying to run my NodeJS app on Elastic Beanstalk. I tried to follow a stackoverflow answer that told me to change my starting script from server.js to main.js, but that didn't work. I'm using env variables that are set up in a .env file that is not a part of my git repository, could this cause this error or is it more because of the starting script?


Should this section in my configuration dashboard be changed to my start file?


enter image description here


Here is my app setup:


Framework: Expressjs


Database: MongoDB


Elastic Beanstalk Server: 64bit Amazon Linux 2014.09 v1.2.0 running Node.js


I checked my logs and found nothing in my /var/log/nginx/error.log and the only error section I could find only contained information as to what could cause an error.



{"status":"SUCCESS","api_version":"1.0","truncated":"false","results":[{"status":"SUCCESS","msg":"","returncode":0,"events":[{"msg":"No start scripts located in package.json. Node.js may have issues starting. Add start scripts or place code in a file named server.js or app.js.","severity":"ERROR","timestamp":1425234947517}]}]}


Here is my package.json file:



{
"name": "expressjs-blog",
"main": "main.js",
"dependencies": {
"body-parser": "1.6.5",
"ejs": "^1.0.0",
"express": "^4.6.1",
"express-paginate": "0.0.2",
"mongoose": "~3.6.15",
"mongoose-paginate": "^3.1.0",
"serve-favicon": "*",
"passport" : "~0.1.17",
"passport-local" : "~0.1.6",
"connect-flash" : "~0.1.1",
"bcrypt-nodejs" : "latest",
"morgan": "~1.0.0",
"cookie-parser": "~1.0.0",
"method-override": "~1.0.0",
"express-session": "~1.0.0",
"aws-sdk": "*"
}
}


Here is my main.js file:



//Load express
var express = require('express');
var app = express();
var router = express.Router(); // get an instance of the router
var bodyParser = require('body-parser'); // configure app to use bodyParser()
var mongoose = require('mongoose');
var passport = require('passport');
var flash = require('connect-flash');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var aws = require('aws-sdk');

app.use(bodyParser.urlencoded({ extended: true})); // get data from a POST method
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use(cookieParser());


var port = process.env.PORT || 8080; // set the port

var DB_CONFIG = process.env.DB_CONFIGURATION;
var AWS_ACCESS_KEY = process.env.AWS_ACCESS_KEY;
var AWS_SECRET_KEY = process.env.AWS_SECRET_KEY;
var S3_BUCKET = process.env.S3_BUCKET;

var blogDB = require('./config/blogDB.js');
mongoose.connect(blogDB.url);




require('./config/passport.js')(passport);


app.set('view engine', 'ejs'); // set ejs as the view engine

app.use(express.static(__dirname + '/public')); // set the public directory

app.use(session({ secret: 'thisisatest' }));
app.use(passport.initialize());
app.use(passport.session());

app.use(flash());


var routes = require('./app/routes');

app.use(routes); // use routes.js


app.listen(port);
console.log('magic is happening on port' + port);




Aucun commentaire:

Enregistrer un commentaire