@@ -34,15 +34,15 @@ var _warn = function warn (...args) {
34
34
console . warn . call ( console , '[WARN] [Spiderable-Middleware]' , ...args ) ;
35
35
} ;
36
36
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 ;
46
46
request . defaultOptions . badStatuses = [ 502 , 503 , 504 , 599 ] ;
47
47
request . defaultOptions . isBadStatus = function ( statusCode , badStatuses ) {
48
48
return badStatuses . includes ( statusCode ) ;
@@ -55,15 +55,15 @@ module.exports = (function () {
55
55
opts = _opts ;
56
56
}
57
57
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 ;
67
67
this . serviceURL = opts . serviceURL || process . env . SPIDERABLE_SERVICE_URL || process . env . PRERENDER_SERVICE_URL || 'https://render.ostr.io' ;
68
68
this . ignoredHeaders = opts . ignoredHeaders || Spiderable . prototype . ignoredHeaders ;
69
69
this . requestOptions = opts . requestOptions || { } ;
@@ -128,7 +128,7 @@ module.exports = (function () {
128
128
throw new Error ( '{serviceURL} is malformed! Must start with protocol http or https' ) ;
129
129
}
130
130
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 ) ;
132
132
this . serviceURL = this . serviceURL . replace ( re . trailingSlash , strs . empty ) . replace ( re . beginningSlash , strs . empty ) ;
133
133
134
134
if ( ignore ) {
@@ -151,14 +151,14 @@ module.exports = (function () {
151
151
var urlObj = url . parse ( req . url , true ) ;
152
152
if ( ( urlObj . query && urlObj . query . _escaped_fragment_ !== void 0 ) || this . botsRE . test ( req . headers [ strs . ua ] || strs . empty ) ) {
153
153
var hasIgnored = false ;
154
- var hasOnly = false ;
154
+ var hasOnly = false ;
155
155
156
156
if ( this . staticExt . test ( urlObj . pathname ) ) {
157
157
return next ( ) ;
158
158
}
159
159
160
160
if ( this . onlyRE ) {
161
- hasOnly = this . onlyRE . test ( urlObj . pathname ) ;
161
+ hasOnly = this . onlyRE . test ( urlObj . pathname ) ;
162
162
hasIgnored = ! hasOnly ;
163
163
}
164
164
@@ -169,13 +169,13 @@ module.exports = (function () {
169
169
if ( Object . prototype . toString . call ( this . only [ i ] ) === strs . objs . string ) {
170
170
if ( this . only [ i ] === urlObj . pathname ) {
171
171
hasIgnored = false ;
172
- hasOnly = true ;
172
+ hasOnly = true ;
173
173
break ;
174
174
}
175
175
} else if ( Object . prototype . toString . call ( this . only [ i ] ) === strs . objs . regexp ) {
176
176
if ( this . only [ i ] . test ( urlObj . pathname ) ) {
177
177
hasIgnored = false ;
178
- hasOnly = true ;
178
+ hasOnly = true ;
179
179
break ;
180
180
}
181
181
} else {
@@ -200,26 +200,26 @@ module.exports = (function () {
200
200
}
201
201
202
202
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 ) ) ;
205
205
206
206
if ( req . headers [ strs . ua ] ) {
207
207
reqUrl += '&bot=' + encodeURIComponent ( req . headers [ strs . ua ] ) ;
208
208
}
209
209
210
- var opts = Object . assign ( { } , this . requestOptions , {
210
+ var opts = Object . assign ( { } , this . requestOptions , {
211
211
uri : reqUrl ,
212
212
auth : this . auth || false ,
213
213
debug : this . debug
214
214
} ) ;
215
215
216
216
try {
217
217
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 ) {
220
220
if ( error ) {
221
221
// DO NOT THROW AN ERROR ABOUT ABORTED REQUESTS
222
- if ( ! req . aborted ) {
222
+ if ( ! req . aborted && error . statusCode !== 499 ) {
223
223
_warn ( 'Error while connecting to external service:' , error ) ;
224
224
next ( ) ;
225
225
}
0 commit comments