Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-ajax-seo

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ajax-seo

It deals with the most popular crawlers (Google, Twitter, Fb, LinkedIn, ...) redirecting them to static files but serving fresh pages to human users.

  • 1.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
2
Weekly downloads
 
Created
Source

node-ajax-seo

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 ;-)

npmjs page

Installation

npm install node-ajax-seo --save

Usage

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).

Examples


	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));
	        }
	    });
	});

Tests

npm test (not yet)

Contributing

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.

Authors

Eric Lara and Santi Pérez, powered by Ondho.

License

MIT

Roadmap

Keywords

FAQs

Package last updated on 28 Jan 2017

Did you know?

Socket

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.

Install

Related posts

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