#How you get Sail.js running on Openshift#
This instruction is tested with:
- Sails.js v0.9.16
- Node.js 0.10 on Openshift ( 05 May 2014)
###1) package.json
If you use the package.json build by sails new Projectname than you have to add a few fields for openshift – so the server can start you app automatically. Sails uses Grunt to build minify css/js and so on. Openshift dont have grunt installed so you have to add this also.
See package.json for an example. The most important part for openshift:
"dependencies": {
"grunt-cli": ">=0.1.13",
"grunt": "~0.4.4",
...
"scripts": {
"start": "node app.js",
"debug": "node debug app.js"
},
"private": true,
"main": "app.js"
###2) config/local.js
In your Sailsconfig (config/local.js) you have to set Host, Port and Environment. See local.js. Example:
host: process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1",
port: process.env.OPENSHIFT_NODEJS_PORT || 8080,
environment: process.env.NODE_ENV || 'development'
###3) .openshift/action_hooks/pre_start_nodejs
On your local machine you can start node app.js --prod if you want to start Sail.js in production-mode. On Openshift you have to create a “pre_start_nodejs”-File. This file is executed before your node-app starts. Here you can set the environment-mode. Also the build-in-grunt from sails dont work right so we manualy do a "grunt prod" befor starting node.
It’s simple:
- Create a new file “pre_start_nodejs” (no file extension) in the folder “.openshift/action_hooks”
- Insert the following code:
#!/bin/bash
export NODE_ENV=production
# If there is a grunt file, run $ grunt prod
if [ -f "${OPENSHIFT_REPO_DIR}"/Gruntfile.js ]; then
(cd "${OPENSHIFT_REPO_DIR}"; node_modules/grunt-cli/bin/grunt prod)
fi
####4.) Git push
You you can make “git push” and enjoy your Sails.js!
My server is started. Unfortunately, server cannot load any views inside "/projectRoot/views", I tried to login to the shell, the "/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/views/user" folder is actually exist, have any idea?
Sending 500 ("Server Error") response:
Error: ENOENT, no such file or directory '/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/views/user/loginview.ejs'
at Object.fs.openSync (fs.js:427:18)
at fs.readFileSync (fs.js:284:15)
at Object.exports.renderFile (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/ejs/lib/ejs.js:312:37)
at module.exports as engine
at View.render (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/view.js:76:8)
at Function.app.render (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/application.js:504:10)
at ServerResponse.res.render (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/response.js:801:7)
at ServerResponse._addResViewMethod.res.view (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/lib/hooks/views/res.view.js:235:16)
at module.exports.loginView (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/api/controllers/UserController.js:10:9)
at routeTargetFnWrapper (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/lib/router/bind.js:178:5)
at callbacks (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at pass (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/router/index.js:145:5)
at nextRoute (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/router/index.js:100:7)
at callbacks (/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/router/index.js:167:11)
at /var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/node_modules/sails/lib/router/bind.js:186:7 { [Error: ENOENT, no such file or directory '/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/views/user/loginview.ejs']
errno: 34,
code: 'ENOENT',
path: '/var/lib/openshift/5503dbfb4382ecf8be00015e/app-root/runtime/repo/views/user/loginview.ejs',
syscall: 'open' }
----------------------------------------SOLVED-----------------------------------------------------
The problem was about case sensitive file name, i name the view as "loginView.ejs" in folder, server runtime was trying to get "loginview.ejs", This works fine on localhost, but openshift seem doesn't accept that