parent
9da8d51f93
commit
5781a0cae4
@ -0,0 +1,48 @@ |
||||
import * as http from 'http'; |
||||
import { spawn } from 'child_process'; |
||||
import * as path from 'path'; |
||||
let backend = require('git-http-backend'); |
||||
import * as zlib from 'zlib'; |
||||
|
||||
const directory = process.argv[2]; |
||||
|
||||
if (!directory) { |
||||
console.error('Please provide a directory as a command line argument.'); |
||||
process.exit(1); |
||||
} |
||||
|
||||
const server = http.createServer((req, res) => { |
||||
|
||||
// Set CORS headers
|
||||
res.setHeader('Access-Control-Allow-Origin', '*'); |
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); |
||||
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); |
||||
res.setHeader('Access-Control-Allow-Credentials', 'true'); |
||||
|
||||
if (req.method === 'OPTIONS') { |
||||
// Handle preflight request
|
||||
res.writeHead(204); |
||||
res.end(); |
||||
return; |
||||
} |
||||
|
||||
const repo = req.url?.split('/')[1]; |
||||
const dir = path.join(directory, 'git', repo || ''); |
||||
console.log(dir); |
||||
const reqStream = req.headers['content-encoding'] === 'gzip' ? req.pipe(zlib.createGunzip()) : req; |
||||
|
||||
reqStream.pipe(backend(req.url || '', (err, service) => { |
||||
if (err) return res.end(err + '\n'); |
||||
|
||||
res.setHeader('content-type', service.type); |
||||
console.log(service.action, repo, service.fields); |
||||
|
||||
const ps = spawn(service.cmd, [...service.args, dir]); |
||||
ps.stdout.pipe(service.createStream()).pipe(ps.stdin); |
||||
|
||||
})).pipe(res); |
||||
}); |
||||
|
||||
server.listen(6868, () => { |
||||
console.log('Server is listening on port 6868'); |
||||
}); |
@ -1,38 +0,0 @@ |
||||
var http = require('http'); |
||||
var spawn = require('child_process').spawn; |
||||
var path = require('path'); |
||||
var backend = require('git-http-backend'); |
||||
var zlib = require('zlib'); |
||||
|
||||
var server = http.createServer(function (req, res) { |
||||
|
||||
// Set CORS headers
|
||||
res.setHeader('Access-Control-Allow-Origin', '*'); |
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); |
||||
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); |
||||
res.setHeader('Access-Control-Allow-Credentials', true); |
||||
|
||||
if (req.method === 'OPTIONS') { |
||||
// Handle preflight request
|
||||
res.writeHead(204); |
||||
res.end(); |
||||
return; |
||||
} |
||||
|
||||
var repo = req.url.split('/')[1]; |
||||
var dir = path.join('/home/bunsen/', 'git', repo); |
||||
console.log(dir); |
||||
var reqStream = req.headers['content-encoding'] == 'gzip' ? req.pipe(zlib.createGunzip()) : req; |
||||
|
||||
reqStream.pipe(backend(req.url, function (err, service) { |
||||
if (err) return res.end(err + '\n'); |
||||
|
||||
res.setHeader('content-type', service.type); |
||||
console.log(service.action, repo, service.fields); |
||||
|
||||
var ps = spawn(service.cmd, service.args.concat(dir)); |
||||
ps.stdout.pipe(service.createStream()).pipe(ps.stdin); |
||||
|
||||
})).pipe(res); |
||||
}); |
||||
server.listen(3000); |
@ -0,0 +1,10 @@ |
||||
|
||||
cd /tmp/ |
||||
rm -rf git/bare.git |
||||
rm -rf git |
||||
mkdir -p git |
||||
cd git |
||||
mkdir bare.git |
||||
cd bare.git |
||||
git init --bare |
||||
cd /tmp/ |
@ -0,0 +1,54 @@ |
||||
import { ChildProcess, spawn } from "child_process" |
||||
import kill from 'tree-kill' |
||||
import init from "../helpers/init" |
||||
let gitserver: ChildProcess |
||||
module.exports = { |
||||
'@disabled': true, |
||||
before: function (browser, done) { |
||||
init(browser, done) |
||||
}, |
||||
after: function (browser) { |
||||
browser.perform((done) => { |
||||
console.log('kill server', gitserver.pid) |
||||
kill(gitserver.pid) |
||||
done() |
||||
}) |
||||
}, |
||||
|
||||
'run server #group1': function (browser) { |
||||
browser.perform(async (done) => { |
||||
gitserver = await spawnGitServer('/tmp/') |
||||
console.log('working directory', process.cwd()) |
||||
done() |
||||
}) |
||||
}, |
||||
'clone a repository': function (browser) { |
||||
console.log('cloning') |
||||
} |
||||
} |
||||
|
||||
async function spawnGitServer(path: string): Promise<ChildProcess> { |
||||
console.log(process.cwd()) |
||||
try { |
||||
const server = spawn('yarn && npx ts-node server.ts', [`${path}`], { cwd: process.cwd() + '/apps/remix-ide-e2e/src/githttpbackend/', shell: true, detached: true }) |
||||
console.log('spawned', server.stdout.closed, server.stderr.closed) |
||||
return new Promise((resolve, reject) => { |
||||
server.stdout.on('data', function (data) { |
||||
console.log(data.toString()) |
||||
if ( |
||||
data.toString().includes('is listening') |
||||
|| data.toString().includes('address already in use') |
||||
) { |
||||
console.log('resolving') |
||||
resolve(server) |
||||
} |
||||
}) |
||||
server.stderr.on('err', function (data) { |
||||
console.log(data.toString()) |
||||
reject(data.toString()) |
||||
}) |
||||
}) |
||||
} catch (e) { |
||||
console.log(e) |
||||
} |
||||
} |
Loading…
Reference in new issue