node-git-server icon indicating copy to clipboard operation
node-git-server copied to clipboard

CORS Headers

Open simplygreatwork opened this issue 6 years ago • 3 comments

I am working with isomorphic-git in the browser. I will be able to connect to node-git-server using a proxy server - but I'm also exploring adding cors headers upon node-git-server requests. But I don't see any way to set a new header without overriding handle() and handlers. Any thoughts on how to approach this?

simplygreatwork avatar Mar 16 '19 04:03 simplygreatwork

So i'm just trying to wrap the handle method and set the CORS headers - not successful yet...

simplygreatwork avatar Mar 16 '19 23:03 simplygreatwork

Making some progress.

npm install --save cors
const cors = require('cors')();
const handle = server.handle.bind(server);
server.handle = function(req, res) {
	cors(req, res, function() {
		handle(req, res);
	});
};

simplygreatwork avatar Mar 17 '19 03:03 simplygreatwork

I think the issue with overriding handle is that you are removing the functionality it had before, we can either expose the ability to introspect on each request, which could be valid for other use cases, or have you tried:

const cors = require('cors')();
const oldHandle = server.handle;
server.handle = function(req, res) {
	cors(req, res, function() {
		oldHandle(req, res);
	});
};

gabrielcsapo avatar Mar 31 '19 17:03 gabrielcsapo