Socket
Socket
Sign inDemoInstall

serve-handler

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serve-handler - npm Package Compare versions

Comparing version 2.3.11 to 2.3.12

2

package.json
{
"name": "serve-handler",
"version": "2.3.11",
"version": "2.3.12",
"description": "The routing foundation of `serve` and static deployments on Now",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -68,8 +68,15 @@ // Native

const applyRewrites = (requestPath, rewrites = []) => {
if (rewrites.length === 0) {
return requestPath;
const applyRewrites = (requestPath, rewrites = [], repetitive) => {
// We need to copy the array, since we're going to modify it.
const rewritesCopy = rewrites.slice();
// If the method was called again, the path was already rewritten
// so we need to make sure to return it.
const fallback = repetitive ? requestPath : null;
if (rewritesCopy.length === 0) {
return fallback;
}
for (let index = 0; index < rewrites.length; index++) {
for (let index = 0; index < rewritesCopy.length; index++) {
const {source, destination} = rewrites[index];

@@ -80,10 +87,10 @@ const target = toTarget(source, destination, requestPath);

// Remove rules that were already applied
rewrites.splice(index, 1);
rewritesCopy.splice(index, 1);
// Check if there are remaining ones to be applied
return applyRewrites(slasher(target), rewrites);
return applyRewrites(slasher(target), rewritesCopy, true);
}
}
return requestPath;
return fallback;
};

@@ -218,4 +225,4 @@

const findRelated = async (current, relativePath, originalStat, extension = '.html') => {
const possible = getPossiblePaths(relativePath, extension);
const findRelated = async (current, relativePath, rewrittenPath, originalStat, extension = '.html') => {
const possible = rewrittenPath ? [rewrittenPath] : getPossiblePaths(relativePath, extension);

@@ -250,3 +257,3 @@ let stats = null;

// need to check for the existance of `.htm` ones.
return findRelated(current, relativePath, originalStat, '.htm');
return findRelated(current, relativePath, rewrittenPath, originalStat, '.htm');
};

@@ -395,6 +402,8 @@

const decodedPath = decodeURIComponent(url.parse(request.url).pathname);
const cleanUrl = applicable(decodedPath, config.cleanUrls);
const redirect = shouldRedirect(decodedPath, config, cleanUrl);
let relativePath = decodeURIComponent(url.parse(request.url).pathname);
let absolutePath = path.join(current, relativePath);
const cleanUrl = applicable(relativePath, config.cleanUrls);
const redirect = shouldRedirect(relativePath, config, cleanUrl);
if (redirect) {

@@ -409,5 +418,2 @@ response.writeHead(redirect.statusCode, {

let relativePath = applyRewrites(decodedPath, config.rewrites);
let absolutePath = path.join(current, relativePath);
let stats = null;

@@ -426,5 +432,7 @@

if ((!stats || stats.isDirectory()) && cleanUrl) {
const rewrittenPath = applyRewrites(relativePath, config.rewrites);
if ((!stats || stats.isDirectory()) && (cleanUrl || rewrittenPath)) {
try {
const related = await findRelated(current, relativePath, handlers.stat);
const related = await findRelated(current, relativePath, rewrittenPath, handlers.stat);

@@ -431,0 +439,0 @@ if (related) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc