expediate 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +138 -0
- package/CONTRIBUTING.md +150 -0
- package/LICENSE +16 -16
- package/README.md +330 -444
- package/dist/apis.d.ts +504 -27
- package/dist/apis.d.ts.map +1 -1
- package/dist/apis.js +618 -107
- package/dist/apis.js.map +1 -1
- package/dist/cjs/index.js +4066 -0
- package/dist/cjs/package.json +1 -0
- package/dist/git.d.ts +72 -9
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +129 -74
- package/dist/git.js.map +1 -1
- package/dist/http-objects.d.ts +26 -0
- package/dist/http-objects.d.ts.map +1 -0
- package/dist/http-objects.js +588 -0
- package/dist/http-objects.js.map +1 -0
- package/dist/index.d.ts +18 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -24
- package/dist/index.js.map +1 -1
- package/dist/jwt-auth.d.ts +158 -57
- package/dist/jwt-auth.d.ts.map +1 -1
- package/dist/jwt-auth.js +447 -207
- package/dist/jwt-auth.js.map +1 -1
- package/dist/middleware.d.ts +476 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +647 -0
- package/dist/middleware.js.map +1 -0
- package/dist/mimetypes.json +882 -1
- package/dist/misc.d.ts +268 -25
- package/dist/misc.d.ts.map +1 -1
- package/dist/misc.js +449 -168
- package/dist/misc.js.map +1 -1
- package/dist/openapi.d.ts +433 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +624 -0
- package/dist/openapi.js.map +1 -0
- package/dist/router-types.d.ts +760 -0
- package/dist/router-types.d.ts.map +1 -0
- package/dist/router-types.js +23 -0
- package/dist/router-types.js.map +1 -0
- package/dist/router.d.ts +37 -201
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +502 -244
- package/dist/router.js.map +1 -1
- package/dist/static.d.ts +3 -3
- package/dist/static.d.ts.map +1 -1
- package/dist/static.js +164 -105
- package/dist/static.js.map +1 -1
- package/docs/THREAT_MODEL.md +52 -0
- package/docs/api-builder-v2-design.md +644 -0
- package/docs/api-builder-v3-design.md +397 -0
- package/docs/api-builder.md +454 -0
- package/docs/benchmark.md +27 -0
- package/docs/body-parsing.md +223 -0
- package/docs/errors.md +359 -0
- package/docs/expediate.png +0 -0
- package/docs/git.md +139 -0
- package/docs/jwt-auth.md +251 -0
- package/docs/logo.svg +12 -0
- package/docs/middleware.md +264 -0
- package/docs/openapi.md +180 -0
- package/docs/router.md +356 -0
- package/docs/static.md +128 -0
- package/docs/wiki.json +123 -0
- package/package.json +47 -8
- package/.npmignore +0 -16
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/dist/git.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface GitHandlerOptions {
|
|
|
17
17
|
* repository: (req) => path.join('/srv/git', req.params.repo + '.git')
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
repository: (req: RouterRequest) => string | null | undefined | false
|
|
20
|
+
repository: (req: RouterRequest) => string | null | undefined | false | Promise<string | null | undefined | false>;
|
|
21
21
|
/**
|
|
22
22
|
* Directory that contains the `git-upload-pack` executable, including a
|
|
23
23
|
* trailing path separator (e.g. `'/usr/lib/git-core/'`).
|
|
@@ -39,6 +39,38 @@ export interface GitHandlerOptions {
|
|
|
39
39
|
*/
|
|
40
40
|
timeout?: number | string;
|
|
41
41
|
}
|
|
42
|
+
export interface GitCreateOption {
|
|
43
|
+
/**
|
|
44
|
+
* Directory that contains the `git` executable, including a trailing path
|
|
45
|
+
* separator (e.g. `'/usr/lib/git-core/'`).
|
|
46
|
+
*
|
|
47
|
+
* Leave empty (default) to locate the binary via the system `PATH`.
|
|
48
|
+
*/
|
|
49
|
+
gitPath?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Human-readable description written to the repository's `description` file.
|
|
52
|
+
*
|
|
53
|
+
* For a bare repository the file is at `<gitDirectory>/description`.
|
|
54
|
+
* For a working-tree repository the file is at `<gitDirectory>/.git/description`.
|
|
55
|
+
*
|
|
56
|
+
* When omitted, no description file is written and Git's default placeholder
|
|
57
|
+
* text is left in place.
|
|
58
|
+
*/
|
|
59
|
+
description?: string;
|
|
60
|
+
/**
|
|
61
|
+
* When `true` (the default), the repository is initialised as a **bare**
|
|
62
|
+
* repository — no working tree is created and Git objects are stored directly
|
|
63
|
+
* inside `gitDirectory`. Bare repositories are the standard choice for
|
|
64
|
+
* server-side hosting because they cannot be accidentally modified by editing
|
|
65
|
+
* files directly.
|
|
66
|
+
*
|
|
67
|
+
* When `false`, a regular repository with a working tree is created (equivalent
|
|
68
|
+
* to running `git init <gitDirectory>` on the command line).
|
|
69
|
+
*
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
bare?: boolean;
|
|
73
|
+
}
|
|
42
74
|
/**
|
|
43
75
|
* Middleware factory that exposes a Git repository over the **Git Smart HTTP
|
|
44
76
|
* protocol** (read-only fetch / clone, via `git-upload-pack`).
|
|
@@ -54,13 +86,11 @@ export interface GitHandlerOptions {
|
|
|
54
86
|
*
|
|
55
87
|
* **Supported endpoints:**
|
|
56
88
|
*
|
|
57
|
-
* | Method | Path
|
|
58
|
-
*
|
|
59
|
-
* | GET | `/info/refs`
|
|
60
|
-
* | POST | `/git-upload-pack
|
|
61
|
-
*
|
|
62
|
-
* Only `git-upload-pack` (fetch / clone) is implemented.
|
|
63
|
-
* `git-receive-pack` (push) is intentionally excluded.
|
|
89
|
+
* | Method | Path | Purpose |
|
|
90
|
+
* |--------|--------------------|----------------------------------------------|
|
|
91
|
+
* | GET | `/info/refs` | Smart HTTP capability advertisement |
|
|
92
|
+
* | POST | `/git-upload-pack` | Pack-file negotiation and transfer |
|
|
93
|
+
* | POST | `/git-receive-pack`| Pack-file publish and transfer |
|
|
64
94
|
*
|
|
65
95
|
* **Compression:** gzip-compressed POST bodies are transparently decompressed
|
|
66
96
|
* before being piped to `git-upload-pack`.
|
|
@@ -69,6 +99,39 @@ export interface GitHandlerOptions {
|
|
|
69
99
|
* @returns An Express-compatible middleware function `(req, res) => void`.
|
|
70
100
|
* @throws {TypeError} When `opt.repository` is not a function.
|
|
71
101
|
*/
|
|
72
|
-
export declare function gitHandler(opt: GitHandlerOptions): (req: RouterRequest, res: RouterResponse) => void
|
|
102
|
+
export declare function gitHandler(opt: GitHandlerOptions): (req: RouterRequest, res: RouterResponse) => void | Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Initialise a new Git repository at `gitDirectory` by running `git init`.
|
|
105
|
+
*
|
|
106
|
+
* By default a **bare** repository is created (no working tree), which is the
|
|
107
|
+
* conventional layout for server-side hosting. Pass `{ bare: false }` to
|
|
108
|
+
* create a standard repository with a working tree instead.
|
|
109
|
+
*
|
|
110
|
+
* @param gitDirectory - Absolute filesystem path of the directory in which
|
|
111
|
+
* the repository will be created. The directory is created by Git if it
|
|
112
|
+
* does not already exist.
|
|
113
|
+
* @param opt - Creation options. All fields are optional.
|
|
114
|
+
* @param opt.gitPath - Directory containing the `git` binary (with trailing
|
|
115
|
+
* separator). Defaults to `''` so that the system `PATH` is used.
|
|
116
|
+
* @param opt.bare - When `true` (default) a bare repository is created
|
|
117
|
+
* (`git init --bare`). When `false` a regular working-tree repository is
|
|
118
|
+
* created (`git init`).
|
|
119
|
+
* @param opt.description - Text written to the repository's `description`
|
|
120
|
+
* file after initialisation. Bare: `<gitDirectory>/description`;
|
|
121
|
+
* non-bare: `<gitDirectory>/.git/description`. Skipped when omitted.
|
|
122
|
+
* @returns A `Promise` that resolves when the repository has been
|
|
123
|
+
* successfully created, or rejects with an error message string when the
|
|
124
|
+
* `git` process fails to start or exits with a non-zero code.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* // Create a bare repository (default — suitable for server hosting)
|
|
129
|
+
* await gitCreate('/srv/git/myproject.git', { description: 'My project' });
|
|
130
|
+
*
|
|
131
|
+
* // Create a regular repository with a working tree
|
|
132
|
+
* await gitCreate('/home/user/myproject', { bare: false });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function gitCreate(gitDirectory: string, opt: GitCreateOption): Promise<void>;
|
|
73
136
|
export default gitHandler;
|
|
74
137
|
//# sourceMappingURL=git.d.ts.map
|
package/dist/git.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAOjE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;OAaG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC;IAEnH;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAwCD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CA6IpH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA2CnF;AAiCD,eAAe,UAAU,CAAC"}
|
package/dist/git.js
CHANGED
|
@@ -19,10 +19,9 @@
|
|
|
19
19
|
* DEALINGS IN THE SOFTWARE.
|
|
20
20
|
*/
|
|
21
21
|
'use strict';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const zlib_1 = require("zlib");
|
|
22
|
+
import { spawn } from 'child_process';
|
|
23
|
+
import { createGunzip } from 'zlib';
|
|
24
|
+
import { writeFileSync } from 'fs';
|
|
26
25
|
// ---------------------------------------------------------------------------
|
|
27
26
|
// PKT-LINE helpers
|
|
28
27
|
// ---------------------------------------------------------------------------
|
|
@@ -46,11 +45,6 @@ const zlib_1 = require("zlib");
|
|
|
46
45
|
* ```
|
|
47
46
|
*/
|
|
48
47
|
function pktLine(str) {
|
|
49
|
-
// BUG FIX: the original used `str.length` (character count / UTF-16 code
|
|
50
|
-
// units) instead of the actual byte length. The Git PKT-LINE spec requires
|
|
51
|
-
// the 4-hex-digit prefix to represent the *byte* count of the whole frame
|
|
52
|
-
// (prefix + payload). For ASCII-only service names this difference is zero,
|
|
53
|
-
// but using Buffer.byteLength is correct and future-proof.
|
|
54
48
|
const byteLen = Buffer.byteLength(str, 'utf8') + 4; // +4 for the 4-char hex prefix itself
|
|
55
49
|
return byteLen.toString(16).padStart(4, '0') + str;
|
|
56
50
|
}
|
|
@@ -77,13 +71,11 @@ const PKT_FLUSH = '0000';
|
|
|
77
71
|
*
|
|
78
72
|
* **Supported endpoints:**
|
|
79
73
|
*
|
|
80
|
-
* | Method | Path
|
|
81
|
-
*
|
|
82
|
-
* | GET | `/info/refs`
|
|
83
|
-
* | POST | `/git-upload-pack
|
|
84
|
-
*
|
|
85
|
-
* Only `git-upload-pack` (fetch / clone) is implemented.
|
|
86
|
-
* `git-receive-pack` (push) is intentionally excluded.
|
|
74
|
+
* | Method | Path | Purpose |
|
|
75
|
+
* |--------|--------------------|----------------------------------------------|
|
|
76
|
+
* | GET | `/info/refs` | Smart HTTP capability advertisement |
|
|
77
|
+
* | POST | `/git-upload-pack` | Pack-file negotiation and transfer |
|
|
78
|
+
* | POST | `/git-receive-pack`| Pack-file publish and transfer |
|
|
87
79
|
*
|
|
88
80
|
* **Compression:** gzip-compressed POST bodies are transparently decompressed
|
|
89
81
|
* before being piped to `git-upload-pack`.
|
|
@@ -92,85 +84,93 @@ const PKT_FLUSH = '0000';
|
|
|
92
84
|
* @returns An Express-compatible middleware function `(req, res) => void`.
|
|
93
85
|
* @throws {TypeError} When `opt.repository` is not a function.
|
|
94
86
|
*/
|
|
95
|
-
function gitHandler(opt) {
|
|
87
|
+
export function gitHandler(opt) {
|
|
96
88
|
if (typeof opt.repository !== 'function')
|
|
97
89
|
throw new TypeError('gitHandler: opt.repository must be a function');
|
|
98
|
-
const
|
|
99
|
-
return (req, res) => {
|
|
90
|
+
const gitHome = opt.gitPath ?? '';
|
|
91
|
+
return async (req, res) => {
|
|
100
92
|
// Resolve the repository path for this request.
|
|
101
|
-
const gitDirectory = opt.repository(req);
|
|
102
|
-
if (!gitDirectory)
|
|
103
|
-
|
|
93
|
+
const gitDirectory = await opt.repository(req);
|
|
94
|
+
if (!gitDirectory) {
|
|
95
|
+
res.status(404).send('Repository not found');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
104
98
|
const urlPath = req.path; // sub-path after the mount prefix
|
|
105
|
-
// ── GET /info/refs?service=git-
|
|
99
|
+
// ── GET /info/refs?service=git-xxxxxx-pack ──────────────────────────
|
|
106
100
|
if (req.method === 'GET' && urlPath === '/info/refs') {
|
|
107
|
-
|
|
108
|
-
// are present, causing `req.queries.url.service` to throw a TypeError.
|
|
101
|
+
let args;
|
|
109
102
|
const service = req.queries?.url?.service;
|
|
110
|
-
if (service
|
|
111
|
-
|
|
103
|
+
if (service === 'git-upload-pack')
|
|
104
|
+
args = buildArgs(opt, ['--stateless-rpc', '--advertise-refs', gitDirectory]);
|
|
105
|
+
else if (service === 'git-receive-pack')
|
|
106
|
+
args = ['--stateless-rpc', '--advertise-refs', gitDirectory];
|
|
107
|
+
else {
|
|
108
|
+
res.status(403).send(`Service ${String(service)} is not supported`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
112
111
|
res.setHeader('Content-Type', `application/x-${service}-advertisement`);
|
|
113
112
|
res.setHeader('Cache-Control', 'no-cache');
|
|
114
113
|
// The Smart HTTP advertisement starts with a PKT-LINE service banner
|
|
115
114
|
// followed by a flush packet (0000), then the git-upload-pack output.
|
|
116
115
|
res.write(pktLine(`# service=${service}\n`));
|
|
117
116
|
res.write(PKT_FLUSH);
|
|
118
|
-
const
|
|
119
|
-
const proc = (0, child_process_1.spawn)(gitBin, args, {
|
|
117
|
+
const proc = spawn(gitHome + service, args, {
|
|
120
118
|
env: { ...process.env, GIT_PROTOCOL: req.headers['git-protocol'] || '' },
|
|
121
119
|
});
|
|
122
|
-
// BUG FIX: the original did not listen for spawn errors (e.g. ENOENT
|
|
123
|
-
// when git is not installed). Without this handler, a missing binary
|
|
124
|
-
// causes an uncaught exception that crashes the server process.
|
|
125
120
|
proc.on('error', (err) => {
|
|
126
|
-
console.error(
|
|
121
|
+
console.error(`[${service} GET] spawn error:`, err.message);
|
|
127
122
|
if (!res.writableEnded)
|
|
128
|
-
res.status(500).send(
|
|
123
|
+
res.status(500).send(`${service} unavailable: ${err.message}`);
|
|
129
124
|
});
|
|
130
125
|
proc.stdout.pipe(res);
|
|
131
126
|
proc.stdout.on('error', (err) => {
|
|
132
|
-
console.warn(
|
|
127
|
+
console.warn(`[${service} GET] stdout error:`, err.message);
|
|
133
128
|
});
|
|
134
|
-
proc.stderr.on('data', (d) => console.error(
|
|
129
|
+
proc.stderr.on('data', (d) => console.error(`[${service} GET]`, d.toString()));
|
|
135
130
|
proc.on('close', (code) => {
|
|
136
131
|
if (code !== 0) {
|
|
137
|
-
console.error(`[
|
|
132
|
+
console.error(`[${service} GET] exited with code ${code}`);
|
|
138
133
|
if (!res.writableEnded)
|
|
139
|
-
res.status(500).send(
|
|
134
|
+
res.status(500).send(`${service} failed`);
|
|
140
135
|
}
|
|
141
136
|
// When code === 0, proc.stdout has already piped all data and called
|
|
142
137
|
// res.end() automatically (default pipe behaviour).
|
|
143
138
|
});
|
|
144
139
|
return;
|
|
145
140
|
}
|
|
146
|
-
// ── POST /git-upload-pack
|
|
147
|
-
if (req.method === 'POST' && urlPath === '/git-upload-pack') {
|
|
148
|
-
const contentType = req.headers['content-type'] || '';
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
141
|
+
// ── POST /git-upload-pack or /git-receive-pack ──────────────────────
|
|
142
|
+
if (req.method === 'POST' && (urlPath === '/git-upload-pack' || urlPath === '/git-receive-pack')) {
|
|
143
|
+
const contentType = (req.headers['content-type']) || '';
|
|
144
|
+
const service = urlPath.substring(1);
|
|
145
|
+
if (contentType !== `application/x-${service}-request`) {
|
|
146
|
+
res.status(415).send('Unsupported Media Type');
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
let args;
|
|
150
|
+
if (service === 'git-upload-pack')
|
|
151
|
+
args = buildArgs(opt, ['--stateless-rpc', gitDirectory]);
|
|
152
|
+
else if (service === 'git-receive-pack')
|
|
153
|
+
args = ['--stateless-rpc', gitDirectory];
|
|
154
|
+
else {
|
|
155
|
+
res.status(403).send(`Service ${service} is not supported`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
res.setHeader('Content-Type', `application/x-${service}-result`);
|
|
157
159
|
res.setHeader('Cache-Control', 'no-cache');
|
|
158
|
-
const
|
|
159
|
-
const proc = (0, child_process_1.spawn)(gitBin, args, {
|
|
160
|
+
const proc = spawn(gitHome + service, args, {
|
|
160
161
|
env: { ...process.env, GIT_PROTOCOL: req.headers['git-protocol'] || '' },
|
|
161
162
|
});
|
|
162
|
-
// BUG FIX: same missing spawn-error handler as the GET branch.
|
|
163
163
|
proc.on('error', (err) => {
|
|
164
|
-
console.error(
|
|
164
|
+
console.error(`[${service} POST] spawn error:`, err.message);
|
|
165
165
|
if (!res.writableEnded)
|
|
166
|
-
res.status(500).send(
|
|
166
|
+
res.status(500).send(`${service} unavailable: ${err.message}`);
|
|
167
167
|
});
|
|
168
168
|
// Transparently decompress gzip-encoded request bodies.
|
|
169
|
-
const encoding = req.headers['content-encoding'];
|
|
169
|
+
const encoding = (req.headers['content-encoding']);
|
|
170
170
|
if (encoding === 'gzip') {
|
|
171
|
-
const gunzip =
|
|
171
|
+
const gunzip = createGunzip();
|
|
172
172
|
gunzip.on('error', (err) => {
|
|
173
|
-
console.warn(
|
|
173
|
+
console.warn(`[${service} POST] gunzip error:`, err.message);
|
|
174
174
|
if (!res.writableEnded)
|
|
175
175
|
res.status(400).send('Failed to decompress request body');
|
|
176
176
|
});
|
|
@@ -181,24 +181,21 @@ function gitHandler(opt) {
|
|
|
181
181
|
}
|
|
182
182
|
proc.stdout.pipe(res);
|
|
183
183
|
proc.stdout.on('error', (err) => {
|
|
184
|
-
console.warn(
|
|
184
|
+
console.warn(`[${service} POST] stdout error:`, err.message);
|
|
185
185
|
});
|
|
186
|
-
|
|
187
|
-
// the GET branch ('[git-upload-pack refs]'), making log messages from
|
|
188
|
-
// the two branches indistinguishable. Corrected to '[git-upload-pack pack]'.
|
|
189
|
-
proc.stderr.on('data', (d) => console.error('[git-upload-pack pack]', d.toString()));
|
|
186
|
+
proc.stderr.on('data', (d) => console.error(`[${service} POST]`, d.toString()));
|
|
190
187
|
proc.on('close', (code) => {
|
|
191
188
|
if (code !== 0) {
|
|
192
|
-
console.error(`[
|
|
189
|
+
console.error(`[${service} POST] exited with code ${code}`);
|
|
193
190
|
if (!res.writableEnded)
|
|
194
|
-
res.status(500).send(
|
|
191
|
+
res.status(500).send(`${service} failed`);
|
|
195
192
|
}
|
|
196
193
|
});
|
|
197
194
|
proc.stdin.on('error', (err) => {
|
|
198
195
|
// EPIPE is expected when the client disconnects mid-stream; it is not
|
|
199
196
|
// a server-side fault and does not require an error response.
|
|
200
197
|
if (err.code !== 'EPIPE')
|
|
201
|
-
console.warn(
|
|
198
|
+
console.warn(`[${service} POST] stdin error:`, err.message);
|
|
202
199
|
});
|
|
203
200
|
return;
|
|
204
201
|
}
|
|
@@ -206,6 +203,72 @@ function gitHandler(opt) {
|
|
|
206
203
|
res.status(404).send('Not found');
|
|
207
204
|
};
|
|
208
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Initialise a new Git repository at `gitDirectory` by running `git init`.
|
|
208
|
+
*
|
|
209
|
+
* By default a **bare** repository is created (no working tree), which is the
|
|
210
|
+
* conventional layout for server-side hosting. Pass `{ bare: false }` to
|
|
211
|
+
* create a standard repository with a working tree instead.
|
|
212
|
+
*
|
|
213
|
+
* @param gitDirectory - Absolute filesystem path of the directory in which
|
|
214
|
+
* the repository will be created. The directory is created by Git if it
|
|
215
|
+
* does not already exist.
|
|
216
|
+
* @param opt - Creation options. All fields are optional.
|
|
217
|
+
* @param opt.gitPath - Directory containing the `git` binary (with trailing
|
|
218
|
+
* separator). Defaults to `''` so that the system `PATH` is used.
|
|
219
|
+
* @param opt.bare - When `true` (default) a bare repository is created
|
|
220
|
+
* (`git init --bare`). When `false` a regular working-tree repository is
|
|
221
|
+
* created (`git init`).
|
|
222
|
+
* @param opt.description - Text written to the repository's `description`
|
|
223
|
+
* file after initialisation. Bare: `<gitDirectory>/description`;
|
|
224
|
+
* non-bare: `<gitDirectory>/.git/description`. Skipped when omitted.
|
|
225
|
+
* @returns A `Promise` that resolves when the repository has been
|
|
226
|
+
* successfully created, or rejects with an error message string when the
|
|
227
|
+
* `git` process fails to start or exits with a non-zero code.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* // Create a bare repository (default — suitable for server hosting)
|
|
232
|
+
* await gitCreate('/srv/git/myproject.git', { description: 'My project' });
|
|
233
|
+
*
|
|
234
|
+
* // Create a regular repository with a working tree
|
|
235
|
+
* await gitCreate('/home/user/myproject', { bare: false });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export function gitCreate(gitDirectory, opt) {
|
|
239
|
+
return new Promise((resolve, reject) => {
|
|
240
|
+
const gitHome = opt.gitPath ?? '';
|
|
241
|
+
const isBare = opt.bare !== false; // default true
|
|
242
|
+
const args = isBare
|
|
243
|
+
? ['init', '--bare', gitDirectory]
|
|
244
|
+
: ['init', gitDirectory];
|
|
245
|
+
const proc = spawn(gitHome + 'git', args, {
|
|
246
|
+
env: { ...process.env },
|
|
247
|
+
});
|
|
248
|
+
proc.on('error', (err) => {
|
|
249
|
+
console.error(`[git init] spawn error:`, err.message);
|
|
250
|
+
reject(`git unavailable: ${err.message}`);
|
|
251
|
+
});
|
|
252
|
+
proc.stdout.on('error', (err) => {
|
|
253
|
+
console.warn(`[git init] stdout error:`, err.message);
|
|
254
|
+
});
|
|
255
|
+
proc.stderr.on('data', (d) => console.error(`[git init]`, d.toString()));
|
|
256
|
+
proc.on('close', (code) => {
|
|
257
|
+
if (code !== 0) {
|
|
258
|
+
return reject('git failed');
|
|
259
|
+
}
|
|
260
|
+
if (opt.description) {
|
|
261
|
+
// Bare repos store the description at the root; working-tree repos
|
|
262
|
+
// store it inside the hidden .git sub-directory.
|
|
263
|
+
const descPath = isBare
|
|
264
|
+
? `${gitDirectory}/description`
|
|
265
|
+
: `${gitDirectory}/.git/description`;
|
|
266
|
+
writeFileSync(descPath, opt.description);
|
|
267
|
+
}
|
|
268
|
+
resolve();
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
}
|
|
209
272
|
// ---------------------------------------------------------------------------
|
|
210
273
|
// Internal helpers
|
|
211
274
|
// ---------------------------------------------------------------------------
|
|
@@ -224,21 +287,13 @@ function gitHandler(opt) {
|
|
|
224
287
|
function buildArgs(opt, trailing) {
|
|
225
288
|
const args = [];
|
|
226
289
|
if (opt.timeout) {
|
|
227
|
-
// BUG FIX: `parseInt` without an explicit radix may misinterpret strings
|
|
228
|
-
// that start with '0' as octal in some environments. Always pass base 10.
|
|
229
290
|
const seconds = parseInt(String(opt.timeout), 10);
|
|
230
291
|
if (!isNaN(seconds) && seconds > 0)
|
|
231
292
|
args.push(`--timeout=${seconds}`);
|
|
232
293
|
}
|
|
233
|
-
// BUG FIX: the original used `opt.bareOnly ? '--strict' : '--no-strict'`.
|
|
234
|
-
// `git-upload-pack` does not accept `--strict` — that flag belongs to
|
|
235
|
-
// `git-receive-pack`. The correct option for upload-pack is `--no-strict`
|
|
236
|
-
// (which relaxes the requirement that the path must be a bare repository).
|
|
237
|
-
// When the caller sets `strict: true` we simply omit `--no-strict`; when
|
|
238
|
-
// `strict` is false (default) we pass `--no-strict` to allow non-bare repos.
|
|
239
294
|
if (!opt.strict)
|
|
240
295
|
args.push('--no-strict');
|
|
241
296
|
return [...args, ...trailing];
|
|
242
297
|
}
|
|
243
|
-
|
|
298
|
+
export default gitHandler;
|
|
244
299
|
//# sourceMappingURL=git.js.map
|
package/dist/git.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,YAAY,CAAC
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,YAAY,CAAC;AAEb,OAAO,EAAE,KAAK,EAAE,MAAY,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,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CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,aAAa,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,MAAM;QACb,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAE3B,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
/**
|
|
3
|
+
* Prepare a raw `http.IncomingMessage` / `http.ServerResponse` pair for router
|
|
4
|
+
* middleware: attach the shared helper prototypes and populate the per-request
|
|
5
|
+
* data fields the helpers (and the router) rely on.
|
|
6
|
+
*
|
|
7
|
+
* This function is idempotent — it exits immediately when `req.queries` is
|
|
8
|
+
* already defined, so it is safe to call multiple times on the same pair (as
|
|
9
|
+
* happens with nested routers sharing one request object).
|
|
10
|
+
*
|
|
11
|
+
* **Fields added to `req`:** `originalUrl`, `path`, `params`, `query`,
|
|
12
|
+
* `queries`, `cookies`, `ip`, `ips`, `protocol`, `secure`, `hostname`,
|
|
13
|
+
* `baseUrl`. Helper methods (`json`, `text`, `formData`, `header`) come from
|
|
14
|
+
* the shared request prototype.
|
|
15
|
+
*
|
|
16
|
+
* **Fields added to `res`:** `locals` and the cookie-signing secret (under a
|
|
17
|
+
* private symbol). Helper methods (`send`, `json`, `status`, `cookie`,
|
|
18
|
+
* `download`, …) come from the shared response prototype.
|
|
19
|
+
*
|
|
20
|
+
* @param req - The raw incoming message to augment.
|
|
21
|
+
* @param res - The raw server response to augment.
|
|
22
|
+
* @param secret - Optional cookie-signing secret.
|
|
23
|
+
* @param trustProxy - When `true`, resolve `req.ip` from `X-Forwarded-For`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function updateHttpObjects(req: http.IncomingMessage, res: http.ServerResponse, secret: string | undefined, trustProxy?: boolean): void;
|
|
26
|
+
//# sourceMappingURL=http-objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-objects.d.ts","sourceRoot":"","sources":["../src/http-objects.ts"],"names":[],"mappings":"AA2CA,OAAO,KAAK,IAAI,MAAQ,MAAM,CAAC;AA8c/B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAU,IAAI,CAAC,eAAe,EACjC,GAAG,EAAU,IAAI,CAAC,cAAc,EAChC,MAAM,EAAO,MAAM,GAAG,SAAS,EAC/B,UAAU,CAAC,EAAE,OAAO,GACnB,IAAI,CAsGN"}
|