thiagoelg commented on code in PR #3450:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3450#discussion_r2822554555


##########
packages/accelerator-git-http-server/src/server.ts:
##########
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as http from "http";
+import * as path from "path";
+import * as fs from "fs";
+import { spawn } from "child_process";
+import serveStatic from "serve-static";
+import finalhandler from "finalhandler";
+
+export interface GitHttpServerConfig {
+  port: number;
+  contentRoot: string;
+  logPrefix?: string;
+}
+
+const gitHttpBackendVariableNames = [
+  "QUERY_STRING",
+  "REMOTE_USER",
+  "CONTENT_LENGTH",
+  "HTTP_CONTENT_ENCODING",
+  "REMOTE_USER",
+  "REMOTE_ADDR",
+  "GIT_COMMITTER_NAME",
+  "GIT_COMMITTER_EMAIL",
+  "CONTENT_TYPE",
+  "PATH_INFO",
+  "GIT_PROJECT_ROOT",
+  "PATH_TRANSLATED",
+  "SERVER_PROTOCOL",
+  "REQUEST_METHOD",
+  "GIT_HTTP_EXPORT_ALL",
+  "GIT_HTTP_MAX_REQUEST_BUFFER",
+];
+
+interface BufferState {
+  header: Buffer[];
+  body: Buffer[];
+  completedHeader: boolean;
+}
+
+/**
+ * Creates and starts a Git HTTP server
+ * @param options Server configuration options
+ * @returns HTTP server instance
+ */
+export function startGitHttpServer(options: GitHttpServerConfig): http.Server {
+  const { port, contentRoot, logPrefix = "git-repo-http-dev-server" } = 
options;
+
+  const log = (message: string) => console.log(`[${logPrefix}] ${message}`);
+
+  if (!fs.existsSync(contentRoot)) {
+    throw new Error(`Can't serve content from non-existent directory 
'${contentRoot}'.`);
+  }
+
+  const serveAsStaticContent = serveStatic(contentRoot);
+
+  const server = http.createServer((req, res) => {
+    // bare git repos
+    if (req.url?.split("/")[1].endsWith(".git")) {

Review Comment:
   There's no need to support deeply nested .git repos.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to