Skip to content

Instantly share code, notes, and snippets.

@selfup
Last active April 27, 2017 21:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selfup/e57983b46477c09078786078fef1042b to your computer and use it in GitHub Desktop.
Save selfup/e57983b46477c09078786078fef1042b to your computer and use it in GitHub Desktop.
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cors())
app.post('/dev_log', function (req, res, next) {
console.log(req.body.message);
res.json({msg: 'This is CORS-enabled for all origins!'})
})
app.listen(3242, function () {
console.log('CORS-enabled web server listening on port 3242')
})
if (process.env.NODE_ENV !== 'production') {
const listen = function listenToErrors(context, method, message) {
return function grabAndBind() {
// debugger;
$.ajax({
url: 'http://localhost:3242/dev_log',
method: 'POST',
data: {
message: arguments[0],
},
dataType: 'json',
success: () => { },
error: () => { },
});
method.apply(context, [message].concat(Array.prototype.slice.apply(arguments)));
};
};
console.log = listen(console, console.log, ':LOG:');
console.error = listen(console, console.error, ':ERROR:');
console.warn = listen(console, console.warn, ':WARN:');
}
@jivanvl
Copy link

jivanvl commented Apr 27, 2017

This is pretty ghetto but clever ❤️

@selfup
Copy link
Author

selfup commented Apr 27, 2017

Haha I mean, micro services right? wahooo 🎉 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment