Sunday 21 May 2017

Express server deployed, not work in openshiftapps but works fine in local

I just deployed my express.js server on openshiftapps and for some reason, one of the routes not working and I get :

Internal Server Error

Same route is fine in local.this route is my root route which only should render my index.ejs file. the other routes working just fine. I share the codes here, I hope you guys can help to see where did I do wrong.

So this is my server.js code :

var express= require('express');
var path = require('path');
var bodyParser = require('body-parser');

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

var app = express();

//View Engine  (We Use ejs)

app.set('views', path.join(__dirname,'views'));
app.set('view engine', 'ejs');

// app.use(express.static(path.join(__dirname,'edaccounting')));

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

app.use('/', index);
app.use('/api/v1/', accountname);

app.listen(8080, function(){
console.log('Server is Started on port 8080');
})

And this is my index.js :

var express= require('express');
var router = express.Router();

router.get('/',function(req,res,next){
res.render('INDEX');   
})

module.exports = router;

so for this route : app.use('/', index); I get Internal server error on the real server but it's working in my local and render the .ejs file. Other route is fine in real server. I used openshiftapps and I build my node.js app there with no errors!



via Emad Dehnavi

No comments:

Post a Comment