diff --git a/core/core.js b/core/core.js index 90af4b36..34b51397 100644 --- a/core/core.js +++ b/core/core.js @@ -38,7 +38,6 @@ let k_static_files = [ {uri: '/client.js', type: 'text/javascript; charset=UTF-8'}, {uri: '/favicon.png', type: 'image/png'}, {uri: '/jszip.min.js', type: 'text/javascript; charset=UTF-8'}, - {uri: '/robots.txt', type: 'text/plain; charset=UTF-8'}, {uri: '/style.css', type: 'text/css; charset=UTF-8'}, {uri: '/tfrpc.js', type: 'text/javascript; charset=UTF-8', headers: {'Access-Control-Allow-Origin': 'null'}}, {uri: '/w3.css', type: 'text/css; charset=UTF-8'}, @@ -1013,8 +1012,6 @@ loadSettings().then(function() { return staticDirectoryHandler(request, response, 'deps/speedscope/', match[1]); } else if (match = /^\/static(\/.*)/.exec(request.uri)) { return staticFileHandler(request, response, null, match[1]); - } else if (request.uri == "/robots.txt") { - return staticFileHandler(request, response, null, request.uri); } else if (match = /^(.*)(\/(?:save|delete)?)$/.exec(request.uri)) { return blobHandler(request, response, match[1], match[2]); } else if ((match = /^\/.well-known\/(.*)/.exec(request.uri)) && request.uri.indexOf("..") == -1) { diff --git a/core/robots.txt b/core/robots.txt deleted file mode 100644 index 84d4fecc..00000000 --- a/core/robots.txt +++ /dev/null @@ -1,3 +0,0 @@ -User-Agent: * -Disallow: /*/*/edit -Allow: / diff --git a/src/httpd.js.c b/src/httpd.js.c index f00774c8..a6b2572e 100644 --- a/src/httpd.js.c +++ b/src/httpd.js.c @@ -508,6 +508,20 @@ static void _httpd_endpoint_hitches(tf_http_request_t* request) tf_free(response); } +static void _httpd_endpoint_robots_txt(tf_http_request_t* request) +{ + if (_httpd_redirect(request)) + { + return; + } + char* response = + "User-Agent: *\n" + "Disallow: /*/*/edit\n" + "Allow: /\n"; + const char* headers[] = { "Content-Type", "text/plain; charset=utf-8" }; + tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0); +} + static void _httpd_endpoint_debug(tf_http_request_t* request) { if (_httpd_redirect(request)) @@ -557,6 +571,7 @@ void tf_httpd_register(JSContext* context) tf_http_set_trace(http, tf_task_get_trace(task)); JS_SetOpaque(httpd, http); + tf_http_add_handler(http, "/robots.txt", _httpd_endpoint_robots_txt, NULL, NULL); tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, NULL, task); tf_http_add_handler(http, "/disconnections", _httpd_endpoint_disconnections, NULL, task); tf_http_add_handler(http, "/hitches", _httpd_endpoint_hitches, NULL, task);