Skip to content

Commit

Permalink
fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Apr 3, 2024
1 parent 29257f9 commit a5ea0d7
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/internal/http/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ const { cwd } = process;
const console = require('internal/console/global');
const { createReadStream } = require('fs');
const { Server } = require('_http_server');
const { URL, formatSymbol, isURLInstance, pathToFileURL } = require('internal/url');
const { URL, isURL, pathToFileURL } = require('internal/url');
const { emitExperimentalWarning, kEmptyObject } = require('internal/util');
const { validateFunction, validatePort } = require('internal/validators');

const dot = /\/(\.|%2[eE])/;
function filterDotFiles(url, fileURL) {
return RegExpPrototypeExec(dot, fileURL.pathname) === null;
}
const urlFormatOptions = { auth: false, search: false, fragment: false };

function createStaticServer(options = kEmptyObject) {
emitExperimentalWarning('http/static');
Expand All @@ -37,7 +36,7 @@ function createStaticServer(options = kEmptyObject) {
log = console.log,
onStart = (host, port) => console.log(`Server started on http://${host}:${port}`),
} = options;
const directoryURL = isURLInstance(directory) ? directory : pathToFileURL(directory);
const directoryURL = isURL(directory) ? directory : pathToFileURL(directory);
// To be used as a base URL, it is necessary that the URL ends with a slash:
const baseDirectoryURL = StringPrototypeEndsWith(directoryURL.pathname, '/') ?
directoryURL : new URL(`${directoryURL}/`);
Expand All @@ -49,7 +48,7 @@ function createStaticServer(options = kEmptyObject) {
const url = new URL(
req.url === '/' || StringPrototypeStartsWith(req.url, '/?') ?
'./index.html' :
'.' + StringPrototypeSlice(new URL(req.url, 'root://')[formatSymbol](urlFormatOptions), 6),
'.' + StringPrototypeSlice(`${new URL(req.url, 'root://')}`, 6),
baseDirectoryURL,
);

Expand Down

0 comments on commit a5ea0d7

Please sign in to comment.