{"id":16815595,"url":"https://github.com/ericzon/node-ajax-seo","last_synced_at":"2025-03-17T12:28:45.998Z","repository":{"id":25743469,"uuid":"29181134","full_name":"ericzon/node-ajax-seo","owner":"ericzon","description":"It deals with the most popular crawlers, redirecting them to static directory and serving fresh pages to human users.","archived":false,"fork":false,"pushed_at":"2017-01-28T12:24:16.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-09T08:31:40.690Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/node-ajax-seo","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericzon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-13T08:54:45.000Z","updated_at":"2022-03-01T15:38:16.000Z","dependencies_parsed_at":"2022-08-24T14:13:23.499Z","dependency_job_id":null,"html_url":"https://github.com/ericzon/node-ajax-seo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericzon%2Fnode-ajax-seo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericzon%2Fnode-ajax-seo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericzon%2Fnode-ajax-seo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericzon%2Fnode-ajax-seo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericzon","download_url":"https://codeload.github.com/ericzon/node-ajax-seo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244033090,"owners_count":20386872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T10:34:55.294Z","updated_at":"2025-03-17T12:28:45.975Z","avatar_url":"https://github.com/ericzon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"node-ajax-seo\n=============\n\nSimple 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](https://www.github.com/ericzon/node-ajax-snapshot) ;-)\n\n[npmjs page](https://www.npmjs.com/package/node-ajax-seo)\n\n## Installation\n\n  npm install node-ajax-seo --save\n\n## Usage\n\n  Options:\n\n    -nonAjaxCondition    (regex|string) regex condition (better choice this) or typical \"if condition\" as string to delimite non-ajax pages.\n    \n    For example: \n\t/((^\\/admin)|(^\\/api)|(\\.)|(^\\/$))/ \n    Same result as:\n        \"(req.url.indexOf('/admin') == -1 \u0026\u0026 req.url.indexOf('/api') == -1 \u0026\u0026 req.url.indexOf('.') == -1 \u0026\u0026 req.url != '/')\"\n\n    -ajaxPath    (string) path to your main SPA .html by default.\n\n    -staticPages.path    (string) path to your static files.\n\n    -staticPages.separator    (string) in your static snapshots, filenames contain some token replacing \"/\" path (\"[---]\" by default).\n\n    -staticPages.basePath.url    (string) basepath is an special case: \"when path is X, serve file Y\" (\"/\" by default).\n\n    -staticPages.basePath.file    (string) (\"index.html\" by default). \n\n    -debug\t\t(boolean) Enables debug messages (false by default).\n\n## Examples\n```javascript\n\n\tvar ajaxSeo = require(\"node-ajax-seo\");\n```\nMinimal config:\n```javascript\n\n\tvar siteConfig = {\n        nonAjaxCondition: /((^\\/admin)|(^\\/api)|(\\.)|(^\\/$))/,\n        ajaxPath: path.join(__dirname, 'assets', 'index.html'),\n        staticPages: {\n            path: path.join(__dirname, 'assets', 'dist', 'static'),\n        }\n    };\n\n    ajaxSeo.dealWithAjax(siteConfig, req, res, next, function cbk(err) {\n        if (err) {\n            console.log(err);\n        }\n        else {\n            console.log(siteConfig.appPrefix+'Sent:', path.join(filePath,fragment));\n        }\n    });\n```\n  Normal config:\n```javascript\n\t\n  \tapp.get(\"/*\", function(req, res,next) {\n\n\t    /**\n\t     * It's necessary to define a pattern that matches with non ajax requests:\n\t     * In this example all the paths are ajax except:\n\t     *\n\t     * - /admin and /api paths.\n\t     * - resource requests.\n\t     * - root\n\t     **/\n\n\t    var siteConfig = {\n\t        nonAjaxCondition: /((^\\/admin)|(^\\/api)|(\\.)|(^\\/$))/,\n\t        ajaxPath: path.join(__dirname, 'assets', 'index.html'),\n\t        staticPages: {\n\t            path: path.join(__dirname, 'assets', 'dist', 'static'),\n\t            separator: \"[---]\",\n\t            basePath: {\n\t                url: \"/\",\n\t                file: \"home.html\"\n\t            }\n\t        },\n\t        debug: false\n\t    };\n\n\t    ajaxSeo.dealWithAjax(siteConfig, req, res, next, function cbk(err) {\n\t        if (err) {\n\t            console.log(err);\n\n\t            // if we don't have snapshot, we can serve 404 page, log miss request into DB, send a mail... whatevevr,\n\t            // but the best option in this case is to generate it and serve it on-the-fly (WIP).\n\t            console.log(siteConfig.appPrefix+\"We serve the  default file caused by the inexistence of the requested one.\");\n\t            //res.status(err.status).end();\n\t            res.sendfile(path.join(siteConfig.staticPages.path,siteConfig.staticPages.basePath.file));\n\t        }\n\t        else {\n\t            console.log(siteConfig.appPrefix+'Sent:', path.join(filePath,fragment));\n\t        }\n\t    });\n\t});\n``` \n\n## Tests\n\n  npm test (not yet)\n\n## Contributing\n\nIn lieu of a formal styleguide, take care to maintain the existing coding style.\nAdd unit tests for any new or changed functionality. Lint and test your code.\n\n## Authors\n\n[Eric Lara](https://www.twitter.com/EricLaraAmat) and [Santi Pérez](https://www.twitter.com/SantiPrzF), powered by [Ondho](http://www.ondho.com).\n\n## License\n\nMIT\n  \n## Roadmap\n\n* Connect with [node-ajax-snapshot](https://www.github.com/ericzon/node-ajax-snapshot) (WIP).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericzon%2Fnode-ajax-seo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericzon%2Fnode-ajax-seo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericzon%2Fnode-ajax-seo/lists"}