-
-
Save 1stvamp/ac8d76e005708b4154ec to your computer and use it in GitHub Desktop.
http-proxy using nextTick to perform task before proxy
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
var httpProxy = require('http-proxy'); | |
var http = require('http'); | |
var config = { | |
"silent": false, | |
"router": { | |
"svc.honshuu.dev/alerts/": "alerts.honshuu.dev", | |
"svc.honshuu.dev/cloud/": "cloud.honshuu.dev:8088", | |
"svc.honshuu.dev/inventory/": "inventory.honshuu.dev", | |
"svc.honshuu.dev/users/": "users.honshuu.dev", | |
"svc.honshuu.dev/metrics/": "metrics-svc", | |
"svc.honshuu.dev/notifications/": "notifications.honshuu.dev" | |
}, | |
"changeOrigin": true | |
}; | |
var proxy = new httpProxy.RoutingProxy(config); | |
var app = http.createServer(); | |
var server = app.listen(8089, '127.0.0.1'); | |
var task = function(request, response, next) { | |
// Do something like insert data from Mongo | |
console.log('Running task..'); | |
next(); | |
} | |
server.on('request', function(request, response) { | |
var next = function() { | |
console.log('Proxying request..'); | |
proxy.proxyRequest(request, response); | |
}; | |
console.log('Queueing task..'); | |
process.nextTick(function() { task(request, response, next); }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment