@es-git/node-git-proxy
TypeScript icon, indicating that this package has built-in type declarations

0.10.0 • Public • Published

node-git-proxy

This is part of the ES-Git project.

Install

npm install --save @es-git/node-git-proxy

Usage

This package can be used as an http proxy for git clients that run in the browser. It is useful because none of the major git hosts support CORS, so you cannot use XHR (or fetch) to clone a git repo in the browser. This package solves this problem by acting as a proxy so you can use the fetch-mixin and the push-mixin in the browser.

//server.js
import * as http from 'http';
import proxy from 'node-git-proxy';

const server = new http.Server(proxy);

// or with koa:
app.use(ctx => proxy(ctx.req, ctx.res));

server.listen(80);

//////////////////////////////////////
//index.js
import mix from '@es-git/mix';
import Memory from '@es-git/memory-repo';
import objectMixin from '@es-git/object-mixin';
import walkersMixin from '@es-git/walkers-mixin';
import fetchMixin from '@es-git/fetch-mixin';
import pushMixin from '@es-git/push-mixin';

async function run(){
  const Repo = mix(Memory)
    .with(objectMixin)
    .with(walkersMixin)
    .with(fetchMixin, fetch)
    .with(pushMixin, fetchIt);

  const repo = new Repo();

  await repo.fetch('http://localhost/github.com/es-git/test-pull.git');

  //TODO: play around with the repo

  await repo.push('http://localhost/github.com/es-git/test-pull.git', 'refs/heads/master');
}

run();

Readme

Keywords

none

Package Sidebar

Install

npm i @es-git/node-git-proxy

Weekly Downloads

1

Version

0.10.0

License

MIT

Unpacked Size

14 kB

Total Files

16

Last publish

Collaborators

  • mariusgundersen