Skip to content

Commit

Permalink
πŸ“¦ v1.6.6
Browse files Browse the repository at this point in the history
- 🧹 Codebase cleanup
- πŸ‘·β€β™‚οΈ Avoid exception on `.abort()`
  • Loading branch information
dr-dimitru committed Jun 9, 2022
1 parent 72f0ebf commit fc7bd72
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
58 changes: 29 additions & 29 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ var _warn = function warn (...args) {
console.warn.call(console, '[WARN] [Spiderable-Middleware]', ...args);
};

request.defaultOptions.debug = false;
request.defaultOptions.headers = { 'User-Agent': 'spiderable-middleware/1.6.4', Accept: '*/*' };
request.defaultOptions.noStorage = true;
request.defaultOptions.rawBody = true;
request.defaultOptions.retry = true;
request.defaultOptions.retries = 3;
request.defaultOptions.retryDelay = 128;
request.defaultOptions.timeout = 102400;
request.defaultOptions.wait = true;
request.defaultOptions.debug = false;
request.defaultOptions.headers = { 'User-Agent': 'spiderable-middleware/1.6.4', Accept: '*/*' };
request.defaultOptions.noStorage = true;
request.defaultOptions.rawBody = true;
request.defaultOptions.retry = true;
request.defaultOptions.retries = 3;
request.defaultOptions.retryDelay = 128;
request.defaultOptions.timeout = 102400;
request.defaultOptions.wait = true;
request.defaultOptions.badStatuses = [502, 503, 504, 599];
request.defaultOptions.isBadStatus = function (statusCode, badStatuses) {
return badStatuses.includes(statusCode);
Expand All @@ -55,15 +55,15 @@ module.exports = (function () {
opts = _opts;
}

this.auth = opts.auth;
this.debug = opts.debug || process.env.DEBUG === 'true' || process.env.DEBUG === true || false;
var ignore = opts.ignore || false;
this.only = opts.only || false;
this.onlyRE = opts.onlyRE || false;
this.botsUA = opts.botsUA || Spiderable.prototype.botsUA;
this.rootURL = opts.rootURL || process.env.ROOT_URL;
this.timeout = opts.timeout || 180000;
this.staticExt = opts.staticExt || re.staticExt;
this.auth = opts.auth;
this.debug = opts.debug || process.env.DEBUG === 'true' || process.env.DEBUG === true || false;
var ignore = opts.ignore || false;
this.only = opts.only || false;
this.onlyRE = opts.onlyRE || false;
this.botsUA = opts.botsUA || Spiderable.prototype.botsUA;
this.rootURL = opts.rootURL || process.env.ROOT_URL;
this.timeout = opts.timeout || 180000;
this.staticExt = opts.staticExt || re.staticExt;
this.serviceURL = opts.serviceURL || process.env.SPIDERABLE_SERVICE_URL || process.env.PRERENDER_SERVICE_URL || 'https://render.ostr.io';
this.ignoredHeaders = opts.ignoredHeaders || Spiderable.prototype.ignoredHeaders;
this.requestOptions = opts.requestOptions || {};
Expand Down Expand Up @@ -128,7 +128,7 @@ module.exports = (function () {
throw new Error('{serviceURL} is malformed! Must start with protocol http or https');
}

this.rootURL = this.rootURL.replace(re.trailingSlash, strs.empty).replace(re.beginningSlash, strs.empty);
this.rootURL = this.rootURL.replace(re.trailingSlash, strs.empty).replace(re.beginningSlash, strs.empty);
this.serviceURL = this.serviceURL.replace(re.trailingSlash, strs.empty).replace(re.beginningSlash, strs.empty);

if (ignore) {
Expand All @@ -151,14 +151,14 @@ module.exports = (function () {
var urlObj = url.parse(req.url, true);
if ((urlObj.query && urlObj.query._escaped_fragment_ !== void 0) || this.botsRE.test(req.headers[strs.ua] || strs.empty)) {
var hasIgnored = false;
var hasOnly = false;
var hasOnly = false;

if (this.staticExt.test(urlObj.pathname)) {
return next();
}

if (this.onlyRE) {
hasOnly = this.onlyRE.test(urlObj.pathname);
hasOnly = this.onlyRE.test(urlObj.pathname);
hasIgnored = !hasOnly;
}

Expand All @@ -169,13 +169,13 @@ module.exports = (function () {
if (Object.prototype.toString.call(this.only[i]) === strs.objs.string) {
if (this.only[i] === urlObj.pathname) {
hasIgnored = false;
hasOnly = true;
hasOnly = true;
break;
}
} else if (Object.prototype.toString.call(this.only[i]) === strs.objs.regexp) {
if (this.only[i].test(urlObj.pathname)) {
hasIgnored = false;
hasOnly = true;
hasOnly = true;
break;
}
} else {
Expand All @@ -200,26 +200,26 @@ module.exports = (function () {
}

reqUrl += '/' + urlObj.pathname;
reqUrl = reqUrl.replace(/([^:]\/)\/+/g, '$1');
reqUrl = (this.serviceURL + '/?url=' + encodeURIComponent(reqUrl));
reqUrl = reqUrl.replace(/([^:]\/)\/+/g, '$1');
reqUrl = (this.serviceURL + '/?url=' + encodeURIComponent(reqUrl));

if (req.headers[strs.ua]) {
reqUrl += '&bot=' + encodeURIComponent(req.headers[strs.ua]);
}

var opts = Object.assign({}, this.requestOptions, {
var opts = Object.assign({}, this.requestOptions, {
uri: reqUrl,
auth: this.auth || false,
debug: this.debug
});

try {
var usedHeaders = [];
var _headersRE = this.headersRE;
var serviceReq = request(opts, function (error, resp) {
var _headersRE = this.headersRE;
var serviceReq = request(opts, function (error, resp) {
if (error) {
// DO NOT THROW AN ERROR ABOUT ABORTED REQUESTS
if (!req.aborted) {
if (!req.aborted && error.statusCode !== 499) {
_warn('Error while connecting to external service:', error);
next();
}
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:spiderable-middleware',
version: '1.6.5',
version: '1.6.6',
summary: 'Allow JavaScript websites to be perfectly crawled and indexed by search engines (SEO)',
git: 'https://github.com/veliovgroup/spiderable-middleware',
documentation: 'README.md'
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spiderable-middleware",
"version": "1.6.5",
"version": "1.6.6",
"description": "Perfect SEO for JavaScript websites. Pre-rendering β€” it's just like SSR with simple integration and no coding",
"main": "./lib/index.js",
"scripts": {
Expand Down Expand Up @@ -47,6 +47,6 @@
"express": "^4.18.1",
"mocha": "^10.0.0",
"request": "^2.88.2",
"underscore": "^1.13.3"
"underscore": "^1.13.4"
}
}

0 comments on commit fc7bd72

Please sign in to comment.