Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
node-ajax-seo
Advanced tools
It deals with the most popular crawlers, redirecting them to static directory and serving fresh pages to human users.
Simple node plugin that deals with the most popular crawlers (Google, Facebook, Twitter, Baidu, LinkedIn), redirecting them to static snapshots while serves fresh pages to human users. It doesn't generate your snapshots, only routes. For that sort of things we have other nice modules ;-)
npm install node-ajax-seo --save
Options:
-nonAjaxCondition (regex|string) regex condition (better choice this) or typical "if condition" as string to delimite non-ajax pages.
For example:
/((^\/admin)|(^\/api)|(\.)|(^\/$))/
Same result as:
"(req.url.indexOf('/admin') == -1 && req.url.indexOf('/api') == -1 && req.url.indexOf('.') == -1 && req.url != '/')"
-ajaxPath (string) path to your main SPA .html by default.
-staticPages.path (string) path to your static files.
-staticPages.separator (string) in your static snapshots, filenames contain some token replacing "/" path ("[---]" by default).
-staticPages.basePath.url (string) basepath is an special case: "when path is X, serve file Y" ("/" by default).
-staticPages.basePath.file (string) ("index.html" by default).
-debug (boolean) Enables debug messages (false by default).
var ajaxSeo = require("node-ajax-seo");
Minimal config:
var siteConfig = {
nonAjaxCondition: /((^\/admin)|(^\/api)|(\.)|(^\/$))/,
ajaxPath: path.join(__dirname, 'assets', 'index.html'),
staticPages: {
path: path.join(__dirname, 'assets', 'dist', 'static'),
}
};
ajaxSeo.dealWithAjax(siteConfig, req, res, next, function cbk(err) {
if (err) {
console.log(err);
}
else {
console.log(siteConfig.appPrefix+'Sent:', path.join(filePath,fragment));
}
});
Normal config:
app.get("/*", function(req, res,next) {
/**
* It's necessary to define a pattern that matches with non ajax requests:
* In this example all the paths are ajax except:
*
* - /admin and /api paths.
* - resource requests.
* - root
**/
var siteConfig = {
nonAjaxCondition: /((^\/admin)|(^\/api)|(\.)|(^\/$))/,
ajaxPath: path.join(__dirname, 'assets', 'index.html'),
staticPages: {
path: path.join(__dirname, 'assets', 'dist', 'static'),
separator: "[---]",
basePath: {
url: "/",
file: "home.html"
}
},
debug: false
};
ajaxSeo.dealWithAjax(siteConfig, req, res, next, function cbk(err) {
if (err) {
console.log(err);
// if we don't have snapshot, we can serve 404 page, log miss request into DB, send a mail... whatevevr,
// but the best option in this case is to generate it and serve it on-the-fly (WIP).
console.log(siteConfig.appPrefix+"We serve the default file caused by the inexistence of the requested one.");
//res.status(err.status).end();
res.sendfile(path.join(siteConfig.staticPages.path,siteConfig.staticPages.basePath.file));
}
else {
console.log(siteConfig.appPrefix+'Sent:', path.join(filePath,fragment));
}
});
});
npm test (not yet)
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
Eric Lara and Santi Pérez, powered by Ondho.
MIT
FAQs
It deals with the most popular crawlers (Google, Twitter, Fb, LinkedIn, ...) redirecting them to static files but serving fresh pages to human users.
The npm package node-ajax-seo receives a total of 1 weekly downloads. As such, node-ajax-seo popularity was classified as not popular.
We found that node-ajax-seo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.