Closed Sherrif closed 9 years ago
I haven't tried, but I believe you should be able to do so without too much complication. Skip Http.Server
and bind Mitm's request
event directly to your Express (or equivalent) handler.
Try something in the style of:
var app = require("express")()
var mitm = require("mitm")()
app.get("/", function(req, res) { res.send("Hello") })
mitm.on("request", app)
Let me know if this works.
Looks like express and connect works well but restify does not. Anyway this is really awesome! Maybe I'll make some library that will allow higher level host mocks or somethings.
Cool. I'm not sure why Restify didn't work for you, but I've never tried it. Mitm should, theoretically at least, work exactly the same API as Http.Server
does.
Anywho, if you look into it and find out why it didn't work, do share. :-)
I'll close this issue for now as there's nothing actionable to do, but we can carry on conversing. ;-)
Is there a way to route certain requests using mitm to an http.Server instance? Specifically I would like to do something like route all requests to a specific domain to a somewhat complex mock server I've created using a library like restify or express.