Skip to content

Commit fc7bd72

Browse files
committed
πŸ“¦ v1.6.6
- 🧹 Codebase cleanup - πŸ‘·β€β™‚οΈ Avoid exception on `.abort()`
1 parent 72f0ebf commit fc7bd72

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

β€Ž.versionsβ€Ž

Lines changed: 3 additions & 3 deletions

β€Žlib/index.jsβ€Ž

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ var _warn = function warn (...args) {
3434
console.warn.call(console, '[WARN] [Spiderable-Middleware]', ...args);
3535
};
3636

37-
request.defaultOptions.debug = false;
38-
request.defaultOptions.headers = { 'User-Agent': 'spiderable-middleware/1.6.4', Accept: '*/*' };
39-
request.defaultOptions.noStorage = true;
40-
request.defaultOptions.rawBody = true;
41-
request.defaultOptions.retry = true;
42-
request.defaultOptions.retries = 3;
43-
request.defaultOptions.retryDelay = 128;
44-
request.defaultOptions.timeout = 102400;
45-
request.defaultOptions.wait = true;
37+
request.defaultOptions.debug = false;
38+
request.defaultOptions.headers = { 'User-Agent': 'spiderable-middleware/1.6.4', Accept: '*/*' };
39+
request.defaultOptions.noStorage = true;
40+
request.defaultOptions.rawBody = true;
41+
request.defaultOptions.retry = true;
42+
request.defaultOptions.retries = 3;
43+
request.defaultOptions.retryDelay = 128;
44+
request.defaultOptions.timeout = 102400;
45+
request.defaultOptions.wait = true;
4646
request.defaultOptions.badStatuses = [502, 503, 504, 599];
4747
request.defaultOptions.isBadStatus = function (statusCode, badStatuses) {
4848
return badStatuses.includes(statusCode);
@@ -55,15 +55,15 @@ module.exports = (function () {
5555
opts = _opts;
5656
}
5757

58-
this.auth = opts.auth;
59-
this.debug = opts.debug || process.env.DEBUG === 'true' || process.env.DEBUG === true || false;
60-
var ignore = opts.ignore || false;
61-
this.only = opts.only || false;
62-
this.onlyRE = opts.onlyRE || false;
63-
this.botsUA = opts.botsUA || Spiderable.prototype.botsUA;
64-
this.rootURL = opts.rootURL || process.env.ROOT_URL;
65-
this.timeout = opts.timeout || 180000;
66-
this.staticExt = opts.staticExt || re.staticExt;
58+
this.auth = opts.auth;
59+
this.debug = opts.debug || process.env.DEBUG === 'true' || process.env.DEBUG === true || false;
60+
var ignore = opts.ignore || false;
61+
this.only = opts.only || false;
62+
this.onlyRE = opts.onlyRE || false;
63+
this.botsUA = opts.botsUA || Spiderable.prototype.botsUA;
64+
this.rootURL = opts.rootURL || process.env.ROOT_URL;
65+
this.timeout = opts.timeout || 180000;
66+
this.staticExt = opts.staticExt || re.staticExt;
6767
this.serviceURL = opts.serviceURL || process.env.SPIDERABLE_SERVICE_URL || process.env.PRERENDER_SERVICE_URL || 'https://render.ostr.io';
6868
this.ignoredHeaders = opts.ignoredHeaders || Spiderable.prototype.ignoredHeaders;
6969
this.requestOptions = opts.requestOptions || {};
@@ -128,7 +128,7 @@ module.exports = (function () {
128128
throw new Error('{serviceURL} is malformed! Must start with protocol http or https');
129129
}
130130

131-
this.rootURL = this.rootURL.replace(re.trailingSlash, strs.empty).replace(re.beginningSlash, strs.empty);
131+
this.rootURL = this.rootURL.replace(re.trailingSlash, strs.empty).replace(re.beginningSlash, strs.empty);
132132
this.serviceURL = this.serviceURL.replace(re.trailingSlash, strs.empty).replace(re.beginningSlash, strs.empty);
133133

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

156156
if (this.staticExt.test(urlObj.pathname)) {
157157
return next();
158158
}
159159

160160
if (this.onlyRE) {
161-
hasOnly = this.onlyRE.test(urlObj.pathname);
161+
hasOnly = this.onlyRE.test(urlObj.pathname);
162162
hasIgnored = !hasOnly;
163163
}
164164

@@ -169,13 +169,13 @@ module.exports = (function () {
169169
if (Object.prototype.toString.call(this.only[i]) === strs.objs.string) {
170170
if (this.only[i] === urlObj.pathname) {
171171
hasIgnored = false;
172-
hasOnly = true;
172+
hasOnly = true;
173173
break;
174174
}
175175
} else if (Object.prototype.toString.call(this.only[i]) === strs.objs.regexp) {
176176
if (this.only[i].test(urlObj.pathname)) {
177177
hasIgnored = false;
178-
hasOnly = true;
178+
hasOnly = true;
179179
break;
180180
}
181181
} else {
@@ -200,26 +200,26 @@ module.exports = (function () {
200200
}
201201

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

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

210-
var opts = Object.assign({}, this.requestOptions, {
210+
var opts = Object.assign({}, this.requestOptions, {
211211
uri: reqUrl,
212212
auth: this.auth || false,
213213
debug: this.debug
214214
});
215215

216216
try {
217217
var usedHeaders = [];
218-
var _headersRE = this.headersRE;
219-
var serviceReq = request(opts, function (error, resp) {
218+
var _headersRE = this.headersRE;
219+
var serviceReq = request(opts, function (error, resp) {
220220
if (error) {
221221
// DO NOT THROW AN ERROR ABOUT ABORTED REQUESTS
222-
if (!req.aborted) {
222+
if (!req.aborted && error.statusCode !== 499) {
223223
_warn('Error while connecting to external service:', error);
224224
next();
225225
}

β€Žpackage.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'ostrio:spiderable-middleware',
3-
version: '1.6.5',
3+
version: '1.6.6',
44
summary: 'Allow JavaScript websites to be perfectly crawled and indexed by search engines (SEO)',
55
git: 'https://github.com/veliovgroup/spiderable-middleware',
66
documentation: 'README.md'

β€Žpackage.jsonβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spiderable-middleware",
3-
"version": "1.6.5",
3+
"version": "1.6.6",
44
"description": "Perfect SEO for JavaScript websites. Pre-rendering β€” it's just like SSR with simple integration and no coding",
55
"main": "./lib/index.js",
66
"scripts": {
@@ -47,6 +47,6 @@
4747
"express": "^4.18.1",
4848
"mocha": "^10.0.0",
4949
"request": "^2.88.2",
50-
"underscore": "^1.13.3"
50+
"underscore": "^1.13.4"
5151
}
5252
}

0 commit comments

Comments
Β (0)