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

node-ajax-seo

Package Overview
Dependencies
Maintainers
1
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, redirecting them to static directory and serving fresh pages to human users.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

node-ajax-seo

Simple node plugin that deals with the most popular crawlers, redirecting them to static directory and serving fresh pages to human users. It doesn't generate your snapshots.

Installation

npm install node-ajax-seo --save

Usage

var ajaxSeo = require("node-ajax-seo");

app.get("/*", function(req, res,next) {

    /**
     * It's necessary to define a pattern that matches with not ajax requests:
     * In this case all the paths are ajax except:
     *
     * - /admin and /api paths.
     * - resource requests.
     * - root
     **/

    var siteConfig = {
        ajaxCondition:{
            pattern: /((^\/admin)|(^\/api)|(\.)|(^\/$))/			// you can specify the condition using regex or typical if condition
            //toEval: "(req.url.indexOf('.') == -1 && req.url != '/' && req.url.indexOf('/admin') == -1)"
        },
        indexPath: path.join(__dirname, 'assets', 'index.html'), 	// your main angular .html by default
        staticPages: {
            path: path.join(__dirname, 'assets', 'dist', 'static'),	// path to your static files
            separator: "[---]",										// in your static files, the filenames contain some token replacing "/" path.
            basePath: {
                url: "/",
                file: "home.html"									// the url basepath is an special case
            }
        },
    	debug: false												// false by default
    };

    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

  • connect with static page generator (WIP)

Keywords

FAQs

Package last updated on 14 Jan 2015

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