Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The example in readme cannot work #294

Open
CHENGCHANGHU opened this issue Sep 14, 2023 · 4 comments
Open

The example in readme cannot work #294

CHENGCHANGHU opened this issue Sep 14, 2023 · 4 comments

Comments

@CHENGCHANGHU
Copy link

I install node-http-mitm-proxy in a node project, paste the example code to file index.js, and run the file. Then I open browser and type www.google.com. But I cannot see log in the terminal.

@NN-Binary
Copy link

Yeah, their CA is not generating automatically anymore

@CHENGCHANGHU
Copy link
Author

Yeah, their CA is not generating automatically anymore

thanks

@Srijan67
Copy link

Srijan67 commented Oct 19, 2023

@CHENGCHANGHU @jasonk @joeferner @NN-Binary I am facing issues in https: . http is working fine. I have pasted code below that i am using and error that i am facing. I can't figure out this . please help me with it.
My ultimate requirement is to read https: request and modify it on my node server

my code is ;
const port = 8081;

const Proxy = require('http-mitm-proxy').Proxy;
const path = require('path')
const fs = require('fs')
const proxy = new Proxy();
var options = {
keyFile: path.resolve('/projects/testmui-api/.http-mitm-proxy/keys/ca.private.key'),
certFile: path.resolve('/projects/testmui-api/.http-mitm-proxy/certs/ca.pem'),
}
proxy.onError((ctx, err, errorKind) => {
// ctx may be null
console.log(ctx, ' error cert')
const url = ctx?.clientToProxyRequest?.url || "";
console.error(${errorKind} on ${url}:, err);
});
proxy.onCertificateRequired = function(hostname, callback) {
return callback(null, {
keyFile: path.resolve('/projects/testmui-api/.http-mitm-proxy/keys/', hostname + '.key'),
certFile: path.resolve('/projects/testmui-api/.http-mitm-proxy/certs/', hostname + '.pem')
});
};
// proxy.onCertificateRequired = function(hostname, callback) {
// return callback(null, {
// keyFile: path.resolve('/projects/testmui-api/.http-mitm-proxy/keys/', hostname + '.key'),
// certFile: path.resolve('/projects/testmui-api/.http-mitm-proxy/certs/', hostname + '.pem'),
// hosts: ["*.mydomain.com"]
// });
// };
proxy.onCertificateMissing = function(ctx, files, callback) {
console.log('Looking for "%s" certificates', ctx.hostname);
console.log('"%s" missing', ctx.files.keyFile);
console.log('"%s" missing', ctx.files.certFile);
};
proxy.onRequest((ctx, callback) => {
console.log('REQUEST: http://' + ctx.clientToProxyRequest.headers.host + ctx.clientToProxyRequest.url);
return callback();
});

proxy._createHttpsServer(options)
proxy.listen({port})
console.log(listening on ${port});

Error screenshots:
image

@Kalisto93
Copy link

Yeah, their CA is not generating automatically anymore

Any ideas how to fix that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants