https://github.com/seo4ajax/connect-s4a
Connect-s4a is a middleware for Connect framework. It provides a easy way to proxy GET requests from non-js clients to SEO4Ajax.
https://github.com/seo4ajax/connect-s4a
ajax middleware module nodejs prerendering seo seo4ajax single-page-applications snapshot
Last synced: about 1 year ago
JSON representation
Connect-s4a is a middleware for Connect framework. It provides a easy way to proxy GET requests from non-js clients to SEO4Ajax.
- Host: GitHub
- URL: https://github.com/seo4ajax/connect-s4a
- Owner: seo4ajax
- Created: 2013-11-30T13:24:50.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2023-07-04T14:48:44.000Z (almost 3 years ago)
- Last Synced: 2025-03-09T22:21:06.606Z (over 1 year ago)
- Topics: ajax, middleware, module, nodejs, prerendering, seo, seo4ajax, single-page-applications, snapshot
- Language: JavaScript
- Homepage:
- Size: 45.9 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Connect-s4a
[SEO4Ajax](https://www.seo4ajax.com) is a service that allows AJAX websites
(e.g. based on Angular, React, Vue.js, Svelte, Backbone, Ember, jQuery etc.) to
be indexable by search engines and social networks.
Connect-s4a is a middleware for the framework
[Connect](https://github.com/senchalabs/connect). It provides an easy way to
proxy bot requests to [SEO4Ajax](https://www.seo4ajax.com) in
[Node.js](https://nodejs.org/) applications.
## Usage
The middleware must be imported before connect or express.
With connect :
var connect_s4a = require('connect-s4a');
var token = "your site token on SEO4Ajax";
var connect = require('connect');
var app = connect();
app.use(connect_s4a(token));
app.use(function(req, res){
res.end('hello world\n');
});
app.listen(3000);
With express 3.x:
var connect_s4a = require('connect-s4a');
var token = "your site token on SEO4Ajax";
var express = require('express');
var app = express.createServer();
app.use(connect_s4a(token));
app.get('/', function(req, res){
res.send('hello world');
});
app.listen(3000);
With express 4.x:
var connect_s4a = require('connect-s4a');
var token = "your site token on SEO4Ajax";
var express = require('express');
var app = express();
app.use(connect_s4a(token));
app.get('/', function(req, res){
res.send('hello world');
});
app.listen(3000);
With Meteor:
import { WebApp } from 'meteor/webapp';
import connect_s4a from 'connect-s4a';
const token = "your site token on SEO4Ajax";
Meteor.startup(() => {
WebApp.connectHandlers.use(connect_s4a(token));
});
The `connect_s4a` function requires one mandatory parameter: the token of the
site on SEO4Ajax. The second parameter is optional, it is an object with the
following property:
- `apiEndPoint`: URL to the API of SEO4Ajax (`"http://api.seo4ajax.com/"` by
default)
- `rootPath`: a path added after the token when calling the API of SEO4Ajax
(`""` by default)
- `includeUserAgents`: a regular expression used to test the user-agent value of
bots
(`/(bot|spider|pinterest|crawler|archiver|flipboard|mediapartners|facebookexternalhit|quora|whatsapp|outbrain|yahoo! slurp|embedly|developers.google.com\/+\/web/snippet|vkshare|w3c_validator|tumblr|skypeuripreview|nuzzel|qwantify|bitrix link preview|XING-contenttabreceiver|Chrome-Lighthouse|mail\.ru)/gi`
by default),
- `ignoreUserAgents`: a regular expression used to ignore the user-agent value
of bots
- `pathPattern`: a regular expression indicating the paths that must be proxied
to SEO4Ajax (`undefined` by default)
## Installation
Via npm :
$ npm install connect-s4a
## How it works
This module checks the presence of a user-agent string identifying bots. If a
bot is detected, the module requests the snapshot from api.seo4ajax.com and
returns it. Otherwise the module ignores the request.
## Requirements
- node (>= 0.10.0)
- connect (>= 0.2.4) or express (>= 0.3.0)
## Tests
node tests/run.js
## License
(The MIT License)
Copyright (c) 2013-2022 Capsule Code
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the 'Software'), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.