Skip to content

Instantly share code, notes, and snippets.

@laerciobernardo
Last active May 24, 2017 14:44
Show Gist options
  • Save laerciobernardo/07f15d8b567ce6dbc7a1abbb82df7b30 to your computer and use it in GitHub Desktop.
Save laerciobernardo/07f15d8b567ce6dbc7a1abbb82df7b30 to your computer and use it in GitHub Desktop.
Setup Openshift to run localhost and online
'use strict'
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
//Handler to provider any function to parse in ObjectId
String.prototype.toObjectId = function() {
var ObjectId = (require('mongoose').Types.ObjectId);
return new ObjectId(this.toString());
};
app.use(bodyParser.urlencoded({extended:true})); // support encoded bodies
app.use(bodyParser.json()); // support json encoded bodies
app.use(express.static(path.join(__dirname, 'public')));
module.exports = app;
const app = require('./app');
let params = [];
(process.env.OPENSHIFT_NODEJS_IP && ( params.push(process.env.OPENSHIFT_NODEJS_IP)));
(process.env.OPENSHIFT_NODEJS_PORT && !(params.push(process.env.OPESHIFT_NODEJS_PORT)) || params.push('3333'));
const cb = () => {
console.log("%s: Server is listening on "+ (params.length == 3 ? '%s' : 'localhost')+":%s", new Date(), ...(params.slice(0, params.length -1)));
};
params.push(cb);
app.listen(...params);
{
"name": "websocket",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.15.2",
"express": "^4.14.0",
"mongoose": "^4.7.6",
"socket.io": "^1.7.2",
"underscore": "^1.8.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment