keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.64k stars 2.21k forks source link

Installing on Openshift, #1316

Closed mharrisweb closed 8 years ago

mharrisweb commented 9 years ago

Hello,

I am trying to get KS setup on Openshift. I can get the site to work locally but cannot get working in openshift, I get various missing module errors:

Error: Cannot find module 'keystone'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17) 

my package.json file:

{
  "name": "node",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "keystone": "latest",
    "underscore": "latest"
  },
  "devDependencies": {
    "grunt": "~0.4.4",
    "grunt-express-server": "~0.4.17",
    "grunt-contrib-jshint": "~0.7.1",
    "grunt-contrib-compass": "^1.0.1",
    "grunt-contrib-csslint": "^0.3.1",
    "grunt-contrib-cssmin": "^0.11.0",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-cssstats": "^1.0.1",
    "grunt-stats": "^0.1.0",
    "jshint-stylish": "~0.1.3",
    "load-grunt-tasks": "~0.4.0",
    "load-grunt-configs": "^0.4.1",
    "grunt-node-inspector": "~0.1.5",
    "time-grunt": "~0.3.1",
    "grunt-concurrent": "~0.5.0",
    "grunt-nodemon": "~0.2.1",
    "open": "0.0.5"
  },
  "engines": {
    "node": ">=0.10.22",
    "npm": ">=1.3.14"
  },
  "scripts": {
    "start": "node web.js"
  },
  "main": "web.js"
}

My web.js:

var keystone = require('keystone');

var db_name = 'node';

// //provide a sensible default for local development
// mongodb_connection_string = 'mongodb://127.0.0.1:27017/' + db_name;
// //take advantage of openshift env vars when available:
// if(process.env.OPENSHIFT_MONGODB_DB_URL){
//   mongodb_connection_string = process.env.OPENSHIFT_MONGODB_DB_URL + db_name;
// }

// default to a 'localhost' configuration:
var connection_string = 'mongodb://xxx:xxx@127.0.0.1:27017/node';
// if OPENSHIFT env variables are present, use the available connection info:
if(process.env.OPENSHIFT_MONGODB_DB_PASSWORD){
  connection_string = process.env.OPENSHIFT_MONGODB_DB_USERNAME + ":" +
  process.env.OPENSHIFT_MONGODB_DB_PASSWORD + "@" +
  process.env.OPENSHIFT_MONGODB_DB_HOST + ':' +
  process.env.OPENSHIFT_MONGODB_DB_PORT + '/' +
  process.env.OPENSHIFT_APP_NAME;
}

console.log(connection_string);

keystone.init({

    'name': 'node',

    'favicon': 'public/favicon.ico',
    'less': 'public',
    'static': ['public'],

    'views': 'templates/views',
    'view engine': 'jade',

    'auto update': true,
    'mongo': connection_string,

    'session': true,
    'auth': true,
    'user model': 'User',
    'cookie secret': 'xxx'
});

// Load your project's Models

keystone.import('models');

keystone.set('routes', require('./routes'));

keystone.start();
creynders commented 9 years ago

There's no apparent reason why it wouldn't work. Did you deploy the node_modules or install them?

P.s.: it's always nice to see people using your modules, load_grunt_configs in this case 😃

mharrisweb commented 9 years ago

Thanks very much for the reply, great plugin.

I npm installed on my localhost, then pushed everything up to openshift..

creynders commented 9 years ago

It's a bit hard to say what goes wrong without some more information. Are the read permissions of node_modules correct? How do you run the app, simply node web.js? Are you sure the node_modules isn't empty? ...

creynders commented 9 years ago

I have no experience with Openshift whatsoever, so it could be this is "normal" behaviour.

mharrisweb commented 9 years ago

Thanks I'll dig deeper and report back.

morenoh149 commented 9 years ago

try the issues related to openshift as well https://github.com/keystonejs/keystone/search?q=openshift&type=Issues&utf8=%E2%9C%93

mharrisweb commented 9 years ago

Thanks for the replies.

Pretty much hit a brick wall with this, still getting missing module errors. There's very little documentation on installing KS with Openshift.

Apparantly if I set cloud-env in my dependancies package.json, it should install all node modules when I build the app.

Its working fine locally but just 503's when I deploy, really frustrating, guess I'll have to look for another cms solution

webteckie commented 9 years ago

@mharrisweb is there a need to set a proper "WORK DIRECTORY" in OpenShift that perhaps you are not setting and so node won't look in the right place for your modules? eg https://developers.openshift.com/en/managing-environment-variables.html#directory-variables