Skip to content

Commit 03d37d6

Browse files
committed
Initial commit
0 parents  commit 03d37d6

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-0
lines changed

.gitignore

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# next.js build output
61+
.next

LICENSE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2018 William Hilton
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# karma-git-http-server-middleware
2+
3+
A karma middleware for '[git-http-backend](https://github.com/substack/git-http-backend)',
4+
originally inspired by '[git-http-server](https://github.com/bahamas10/node-git-http-server)'
5+
6+
## How to use
7+
8+
```sh
9+
npm install --save-dev karma-git-http-server-middleware
10+
```
11+
12+
In your `karma.config.js`, add:
13+
14+
```
15+
beforeMiddleware: ['git-http-server'],
16+
```
17+
18+
Then in your JS code, you can reference git repos on disk via `http://localhost:9876/path/to/repo.git`.
19+
20+
This is useful for testing `isomorphic-git` and applications built using it.
21+
22+
## Examples
23+
24+
See <https://github.com/isomorphic-git/isomorphic-git/tree/master/__tests__>
25+
26+
## Dependencies
27+
28+
- [git-http-backend](https://github.com/substack/git-http-backend): serve a git repository over http
29+
30+
## License
31+
32+
MIT

index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var path = require('path');
2+
var fs = require('fs');
3+
var factory = require('./middleware')
4+
5+
module.exports = {
6+
'middleware:git-http-server': ['factory', factory]
7+
};

middleware.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var spawn = require('child_process').spawn;
2+
var path = require('path').posix;
3+
var url = require('url');
4+
var backend = require('git-http-backend');
5+
6+
function getGitDir (req) {
7+
var u = url.parse(req.url)
8+
if (req.method === 'GET' && u.pathname.endsWith('/info/refs')) {
9+
return u.pathname.replace(/\/info\/refs$/, '').replace(/^\//, '')
10+
}
11+
if (req.method === 'POST' && req.headers['content-type'] === 'application/x-git-upload-pack-request') {
12+
return u.pathname.replace(/\/git-upload-pack$/, '').replace(/^\//, '')
13+
}
14+
if (req.method === 'POST' && req.headers['content-type'] === 'application/x-git-receive-pack-request') {
15+
return u.pathname.replace(/\/git-receive-pack$/, '').replace(/^\//, '')
16+
}
17+
return null
18+
}
19+
20+
module.exports = function factory() {
21+
return function middleware (req, res, next) {
22+
var gitdir = getGitDir(req);
23+
if (gitdir == null) return next();
24+
25+
req.pipe(backend(req.url, function (err, service) {
26+
if (err) {
27+
res.statusCode = 500;
28+
res.end(err + '\n');
29+
return;
30+
}
31+
32+
res.setHeader('content-type', service.type);
33+
console.log('[git-http-server] ' + service.cmd + ' ' + service.args.concat(gitdir).join(' '))
34+
var ps = spawn(service.cmd, service.args.concat(gitdir));
35+
ps.stdout.pipe(service.createStream()).pipe(ps.stdin);
36+
})).pipe(res);
37+
}
38+
}

package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "karma-git-http-server-middleware",
3+
"version": "1.0.0",
4+
"description": "A karma middleware for 'git-http-backend'",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/isomorphic-git/karma-git-http-server-middleware.git"
12+
},
13+
"keywords": [
14+
"karma-plugin",
15+
"karma-middleware",
16+
"git-http-server",
17+
"git-http-backend"
18+
],
19+
"author": "William Hilton <[email protected]>",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/isomorphic-git/karma-git-http-server-middleware/issues"
23+
},
24+
"homepage": "https://github.com/isomorphic-git/karma-git-http-server-middleware#readme",
25+
"dependencies": {
26+
"git-http-backend": "^1.0.2"
27+
}
28+
}

0 commit comments

Comments
 (0)