Skip to content

Commit

Permalink
fast-url-parser -> url
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan committed Jan 21, 2025
1 parent 172dff1 commit c85ba71
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

* Switches from 'fast-url-parser' to Node's built-in URL parser.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"compression": "^1.7.0",
"connect": "^3.7.0",
"destroy": "^1.0.4",
"fast-url-parser": "^1.1.3",
"glob-slasher": "^1.0.1",
"is-url": "^1.2.2",
"join-path": "^1.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
const _ = require("lodash");
const { i18nContentOptions } = require("../utils/i18n");
const pathutils = require("../utils/pathutils");
const url = require("fast-url-parser");
const url = require("url");

/**
* We cannot redirect to "", redirect to "/" instead.
Expand All @@ -40,7 +40,7 @@ module.exports = function () {

const parsedUrl = url.parse(req.url);
const pathname = pathutils.normalizeMultiSlashes(parsedUrl.pathname);
const search = parsedUrl.search || "";
const search = parsedUrl.search ?? "";

const cleanUrlRules = !!_.get(req, "superstatic.cleanUrls");

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

const _ = require("lodash");
const slasher = require("glob-slasher");
const urlParser = require("fast-url-parser");
const urlParser = require("url");
const onHeaders = require("on-headers");
const patterns = require("../utils/patterns");

Expand Down
7 changes: 5 additions & 2 deletions src/middleware/rewrites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

const slasher = require("glob-slasher"); // eslint-disable-line @typescript-eslint/no-var-requires
const urlParser = require("fast-url-parser"); // eslint-disable-line @typescript-eslint/no-var-requires
import * as urlParser from "url"; // eslint-disable-line @typescript-eslint/no-var-requires
import { NextFunction } from "connect";
import { IncomingMessage, ServerResponse } from "http";

Expand Down Expand Up @@ -50,7 +50,10 @@ module.exports = function () {
next: NextFunction,
) {
const rewrites = matcher(req.superstatic.rewrites ?? []);
const pathname: string = urlParser.parse(req.url).pathname;
if (!req.url) {
return next();
}
const pathname = urlParser.parse(req.url).pathname;
const match = rewrites(slasher(pathname));

if (!match) {
Expand Down

0 comments on commit c85ba71

Please sign in to comment.