Last active
April 27, 2017 21:21
-
-
Save selfup/e57983b46477c09078786078fef1042b to your computer and use it in GitHub Desktop.
This file contains 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 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') | |
}) |
This file contains 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
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:'); | |
} | |
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
This is pretty ghetto but clever ❤️