diff --git a/doc/api/http.md b/doc/api/http.md index 77348a7d1b6e14..f5d04526f554b1 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -3241,20 +3241,20 @@ request will be blocked. If `port` is omitted or is 0, the operating system will assign an arbitrary unused port, which it's output will be the standard output. -Also accessible via `require('node:http/server')`. +Also accessible via `require('node:http/static')`. ```bash # Starts serving the cwd on a random port: -node -r node:http/server +node -r node:http/static node -e 'http.createStaticServer()' # To start serving on the port 8080 using /path/to/dir as the root: -node -r node:http/server /path/to/dir --port 8080 +node -r node:http/static /path/to/dir --port 8080 node -e 'http.createStaticServer({directory: "/path/to/dir", port: 8080})' # Same as above, but exposing your local file system to the whole # IPv4 network: -node -r node:http/server /path/to/dir --port 8080 --host 0.0.0.0 +node -r node:http/static /path/to/dir --port 8080 --host 0.0.0.0 node -e 'http.createStaticServer({directory: "/path/to/dir", port: 8080, host: "0.0.0.0"})' ``` diff --git a/lib/http.js b/lib/http.js index a92fcd4df3f7ad..70e551627848be 100644 --- a/lib/http.js +++ b/lib/http.js @@ -43,7 +43,7 @@ const { Server, ServerResponse } = require('_http_server'); -const createStaticServer = require('http/server'); +const createStaticServer = require('http/static'); let maxHeaderSize; /** diff --git a/lib/http/server.js b/lib/http/static.js similarity index 97% rename from lib/http/server.js rename to lib/http/static.js index 2f583c904e89d4..793dfdc9c011f8 100644 --- a/lib/http/server.js +++ b/lib/http/static.js @@ -23,8 +23,6 @@ const { emitExperimentalWarning, kEmptyObject } = require('internal/util'); const { getOptionValue } = require('internal/options'); const { validateFunction, validatePort } = require('internal/validators'); -emitExperimentalWarning('http/server'); - if (module.isPreloading) { const requiredModules = getOptionValue('--require'); if (ArrayPrototypeIncludes(requiredModules, `node:${module.id}`) || @@ -41,8 +39,8 @@ if (module.isPreloading) { }, } }); nextTick(createStaticServer, { directory: process.argv[1], port, host }); - process.env.NODE_REPL_EXTERNAL_MODULE = 'node:http/server'; - process.argv[1] = 'node:http/server'; + process.env.NODE_REPL_EXTERNAL_MODULE = 'node:http/static'; + process.argv[1] = 'node:http/static'; } } @@ -51,6 +49,8 @@ function filterDotFiles(url, fileURL) { } function createStaticServer(options = kEmptyObject) { + emitExperimentalWarning('http/static'); + const { directory = cwd(), port, diff --git a/test/parallel/test-http-createstaticserver.js b/test/parallel/test-http-createstaticserver.js index 9d0d7e1a9812b1..86cf755df1dcf7 100644 --- a/test/parallel/test-http-createstaticserver.js +++ b/test/parallel/test-http-createstaticserver.js @@ -3,7 +3,7 @@ const { mustCall } = require('../common'); const fixtures = require('../common/fixtures'); const assert = require('node:assert'); const { MIMEType } = require('node:util'); -const createStaticServer = require('node:http/server'); +const createStaticServer = require('node:http/static'); [0, 1, 1n, '', '1', true, false, NaN, Symbol(), {}, []].forEach((filter) => { assert.throws(() => createStaticServer({ filter }), { code: 'ERR_INVALID_ARG_TYPE' });