Monday, 8 May 2017

Express server errors on production

Hello I am trying to deploy my first app with MEAN stack.

I am using debian with nginx.

It seems to works fine ( I see front end with login ) but when I am trying to login I am getting ERR CONNECTION REFUSED.

I am starting my server.js by pm2 start server.js And it started.

But when I am trying to do something in my pm2 log file are errors:

0|server   | Server listening on port 3008

/root/.pm2/logs/server-error-0.log last 15 lines:
0|server   |     at next (/srv/myapp/server/node_modules/express/lib/router/index.js:275:10)
0|server   |     at jsonParser (/srv/myapp/server/node_modules/body-parser/lib/types/json.js:103:7)
0|server   |     at Layer.handle [as handle_request] (/srv/myapp/server/node_modules/express/lib/router/layer.js:95:5)
0|server   |     at trim_prefix (/srv/myapp/server/node_modules/express/lib/router/index.js:317:13)
0|server   | Error
0|server   |     at middleware (/srv/myapp/server/node_modules/express-jwt/lib/index.js:80:21)
0|server   |     at /srv/myapp/server/node_modules/express-unless/index.js:47:5
0|server   |     at Layer.handle [as handle_request] (/srv/myapp/server/node_modules/express/lib/router/layer.js:95:5)
0|server   |     at trim_prefix (/srv/aliasownia/server/node_modules/express/lib/router/index.js:317:13)
0|server   |     at /srv/myapp/server/node_modules/express/lib/router/index.js:284:7
0|server   |     at Function.process_params (/srv/aliasownia/server/node_modules/express/lib/router/index.js:335:12)
0|server   |     at next (/srv/myapp/server/node_modules/express/lib/router/index.js:275:10)
0|server   |     at jsonParser (/srv/myapp/server/node_modules/body-parser/lib/types/json.js:103:7)
0|server   |     at Layer.handle [as handle_request] (/srv/myapp/server/node_modules/express/lib/router/layer.js:95:5)
0|server   |     at trim_prefix (/srv/myapp/server/node_modules/express/lib/router/index.js:317:13)

server.js

require('rootpath')();
var express = require('express');
var app = express();
var cors = require('cors');
var bodyParser = require('body-parser');
var expressJwt = require('express-jwt');
var config = require('config.json');

app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// use JWT auth to secure the api
app.use(expressJwt({ secret: config.secret }).unless({ path: ['/users/authenticate', '/users/register'] }));

// routes
app.use('/users', require('./controllers/users.controller'));

// start server
var port = process.env.NODE_ENV === 'production' ? 3008 : 4000;
var server = app.listen(port, function () {
    console.log('Server listening on port ' + port);
});

config.json

{
    "connectionString": "mongodb://localhost:27017/mydb",
    "apiUrl": "http://mydomain:3008",
    "secret": "My secret"
}



via Defus

No comments:

Post a Comment