diff --git a/cgit.c b/cgit.c
index 9617124..fc9b18b 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1091,6 +1091,52 @@ int cmd_main(int argc, const char **argv)
cgit_parse_url(ctx.qry.url);
}
+ // return static files for cgit.css, cgit.png, favicon.ico and robots.txt
+ const char *script_name = ctx.env.script_name;
+ if (script_name &&
+ (
+ !strcmp(script_name, "/cgit.css")
+ || !strcmp(script_name, "/cgit.png")
+ || !strcmp(script_name, "/cgit.js")
+ || !strcmp(script_name, "/favicon.ico")
+ || !strcmp(script_name, "/robots.txt")
+ )
+ ) {
+ // files are in the same directory as the cgit binary
+ char filename[1024];
+ snprintf(filename, sizeof(filename), "%s/%s", dirname(argv[0]), script_name + 1);
+ struct stat st;
+ if (!stat(filename, &st)) {
+ FILE *f = fopen(filename, "r");
+ if (f) {
+ const char* ext = strrchr(script_name, '.');
+ if (ext && !strcmp(ext, ".css"))
+ ctx.page.mimetype = "text/css";
+ else if (ext && !strcmp(ext, ".png"))
+ ctx.page.mimetype = "image/png";
+ else if (ext && !strcmp(ext, ".ico"))
+ ctx.page.mimetype = "image/x-icon";
+ else if (ext && !strcmp(ext, ".js"))
+ ctx.page.mimetype = "application/javascript";
+
+ char *buf = xmalloc(st.st_size);
+ fread(buf, 1, st.st_size, f);
+ fclose(f);
+ cgit_print_http_headers();
+ fwrite(buf, 1, st.st_size, stdout);
+ free(buf);
+ return 0;
+ }
+ }
+ else
+ {
+ ctx.page.status = 404;
+ ctx.page.statusmsg = "Not Found";
+ cgit_print_http_headers();
+ return 0;
+ }
+ }
+
/* Before we go any further, we set ctx.env.authenticated by checking to see
* if the supplied cookie is valid. All cookies are valid if there is no
* auth_filter. If there is an auth_filter, the filter decides. */
diff --git a/test.sh b/test.sh
index 2dd3214..1fb2658 100755
--- a/test.sh
+++ b/test.sh
@@ -1,8 +1,9 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p
-make all || exit 1
+make all -j$(nproc) || exit 1
#bozohttpd -c ./cgit -I 9000 . -f -V -C '' cgit -p .
+rm -rf test_utils
mkdir test_utils
nix build nixpkgs#nginx --out-link test_utils/nginx
nix build nixpkgs#fcgiwrap --out-link test_utils/fcgiwrap
|