From c0bfb097d90fa459509cbffaf875f1422cc1e6a8 Mon Sep 17 00:00:00 2001 From: Rhythm Bansal Date: Fri, 28 Oct 2022 03:39:43 +0530 Subject: [PATCH 1/4] added code for creating robots.txt --- lib/http-server.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/http-server.js b/lib/http-server.js index dfe4c474..f18ce417 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -110,18 +110,25 @@ function HttpServer(options) { } : null)); } - if (options.robots) { - before.push(function (req, res) { - if (req.url === '/robots.txt') { - res.setHeader('Content-Type', 'text/plain'); - var robots = options.robots === true - ? 'User-agent: *\nDisallow: /' - : options.robots.replace(/\\n/, '\n'); + // if (options.robots) { + // before.push(function (req, res) { + // if (req.url === '/robots.txt') { + // res.setHeader('Content-Type', 'text/plain'); + // var robots = options.robots === true + // ? 'User-agent: *\nDisallow: /' + // : options.robots.replace(/\\n/, '\n'); - return res.end(robots); - } + // return res.end(robots); + // } - res.emit('next'); + // res.emit('next'); + // }); + // } + + if (options.robots) { + fs.appendFile(`${this.root}/robots.txt`, 'User-agent: *\nDisallow: /', function (err) { + if (err) throw err; + // console.log('robots.txt created!'); }); } From 0dd1aa6b6d7bb9d3b105c8b8969b30caa18fdbfe Mon Sep 17 00:00:00 2001 From: Rhythm Bansal Date: Fri, 28 Oct 2022 03:51:25 +0530 Subject: [PATCH 2/4] updated description for --robots --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ffbbc1f..6d899a1e 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ This will install `http-server` globally so that it may be run from the command |`-S`, `--tls` or `--ssl` |Enable secure request serving with TLS/SSL (HTTPS)|`false`| |`-C` or `--cert` |Path to ssl cert file |`cert.pem` | |`-K` or `--key` |Path to ssl key file |`key.pem` | -|`-r` or `--robots` | Automatically provide a /robots.txt (The content of which defaults to `User-agent: *\nDisallow: /`) | `false` | +|`-r` or `--robots` | Automatically creates a /robots.txt file (The content of which defaults to `User-agent: *\nDisallow: /`) | `false` | |`--no-dotfiles` |Do not show dotfiles| | |`--mimetypes` |Path to a .types file for custom mimetype definition| | |`-h` or `--help` |Print this list and exit. | | From 9d9517359901052b467f76b4c19e55706835d741 Mon Sep 17 00:00:00 2001 From: Rhythm Bansal Date: Fri, 28 Oct 2022 03:52:52 +0530 Subject: [PATCH 3/4] editted description for --robots --- bin/http-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/http-server b/bin/http-server index 7c597fa8..949a141c 100755 --- a/bin/http-server +++ b/bin/http-server @@ -56,7 +56,7 @@ if (argv.h || argv.help) { ' -C --cert Path to TLS cert file (default: cert.pem)', ' -K --key Path to TLS key file (default: key.pem)', '', - ' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]', + ' -r --robots Creates a /robots.txt file [User-agent: *\\nDisallow: /]', ' --no-dotfiles Do not show dotfiles', ' --mimetypes Path to a .types file for custom mimetype definition', ' -h --help Print this list and exit.', From cae8040341d0c139ee913f4e17fdb8d7ccbf7b71 Mon Sep 17 00:00:00 2001 From: Rhythm Bansal Date: Fri, 28 Oct 2022 03:54:56 +0530 Subject: [PATCH 4/4] updated description for --robots --- doc/http-server.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/http-server.1 b/doc/http-server.1 index 8e2796e6..2c610c39 100644 --- a/doc/http-server.1 +++ b/doc/http-server.1 @@ -118,8 +118,8 @@ Passphrase will be read from NODE_HTTP_SERVER_SSL_PASSPHRASE (if set) .TP .BI \-r ", " \-\-robots " " [\fIUSER\-AGENT\fR] -Respond to /robots.txt request. -If not specified, uses "User-agent: *\\nDisallow: /]" +Creates a /robots.txt file. +Defaults to ["User-agent: *\\nDisallow: /]" .TP .BI \-\-no\-dotfiles