Last active
May 24, 2017 14:44
-
-
Save laerciobernardo/07f15d8b567ce6dbc7a1abbb82df7b30 to your computer and use it in GitHub Desktop.
Setup Openshift to run localhost and online
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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