Socket
Book a DemoInstallSign in
Socket

next-htaccess-generator

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-htaccess-generator - npm Package Compare versions

Comparing version

to
1.0.3

38

index.js

@@ -13,8 +13,10 @@ #!/usr/bin/env node

function parseSlug(inputString) {
return inputString.replace(/\[(.*?)\]/g, '([^/]+)');
const fileNameWithoutExt = path.parse(inputString).name;
const dirName = path.posix.dirname(inputString);
const dirNameWithoutLeadingDot = dirName.replace(/^\.\//, '');
return `${dirNameWithoutLeadingDot}/${fileNameWithoutExt}`.replace(/\[(.*?)\]/g, '([^/]+)');
}
// Define the folder path you want to scan
const folderPath = config.buildPath;
// console.log("folder", folderPath)
// Function to recursively list HTML files

@@ -43,4 +45,2 @@ function listHtmlFiles(dir, fileList) {

let htaccess = `<IfModule mod_rewrite.c>\n RewriteEngine On\n

@@ -52,23 +52,19 @@ RewriteBase / \n`;

if (!config.include404 && path.includes("404")) {
return
}
const parsedSlug = parseSlug(path)
const parts = parsedSlug.split('/');
const folder = parts.slice(0, -1).join('/');
const rule = `RewriteRule ^${folder}/$ ${path} [L]\n`;
htaccess += ` #${folder}\n`;
htaccess += ` ${rule}`;
});
return
}
const parsedSlug = parseSlug(path)
htaccess += ` #${path}\n`;
htaccess += ` RewriteRule ^${(parsedSlug.replace("./", '')).replace("/index", "")}/$ ${path} [L]\n`;
});
htaccess += ` RewriteCond %{REQUEST_FILENAME} !-f \n
RewriteCond %{REQUEST_FILENAME} !-d \n
RewriteRule ^(.*)$ /404/404.html [L] \n</IfModule>`;
htaccess += ` RewriteCond %{REQUEST_FILENAME} !-f \n
RewriteCond %{REQUEST_FILENAME} !-d \n
RewriteRule ^(.*)$ /404/404.html [L] \n</IfModule>`;
// Write the rules to .htaccess file
// Write the rules to .htaccess file
fs.writeFileSync(path.join(config.outputPath,'.htaccess'), htaccess);
fs.writeFileSync(path.join(config.outputPath,'.htaccess'), htaccess);
console.log('Successfully generated .htaccess file');
console.log('Successfully generated .htaccess file');
}
generateHtaccess()
{
"name": "next-htaccess-generator",
"version": "1.0.2",
"version": "1.0.3",
"description": "This is a simple package to generate htaccess file from next build.",

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.