|
22 | 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
23 | 23 | */ |
24 | 24 | var API, Addons, BCRYPT, ClassHelper, MORGAN, PluginHelper, RESTIFY, |
25 | | - splice = [].splice, |
26 | | - indexOf = [].indexOf; |
| 25 | + splice = [].splice; |
27 | 26 |
|
28 | 27 | RESTIFY = require('restify'); |
29 | 28 |
|
|
39 | 38 | Addons = ["./addons/Fs", "./addons/Os", "./addons/Net"]; |
40 | 39 |
|
41 | 40 | API = (function() { |
42 | | - var _request, _response, addon, i, index, len, useRestifyPlugin; |
| 41 | + var _request, _response, addon, i, index, len; |
43 | 42 |
|
44 | 43 | class API extends ClassHelper { |
45 | 44 | constructor(options) { |
|
181 | 180 |
|
182 | 181 | // Cross-Origin Resource Sharing |
183 | 182 | cors(opts) { |
184 | | - return useRestifyPlugin("CORS", opts); |
| 183 | + return this.useRestifyPlugin("CORS", opts); |
185 | 184 | } |
186 | 185 |
|
187 | 186 | // Body parser |
188 | 187 | bodyParser(opts) { |
189 | | - return useRestifyPlugin("bodyParser", opts); |
| 188 | + return this.useRestifyPlugin("bodyParser", opts); |
190 | 189 | } |
191 | 190 |
|
192 | 191 | // Accept parser |
193 | 192 | acceptParser(opts) { |
194 | | - return useRestifyPlugin("acceptParser", opts); |
| 193 | + return this.useRestifyPlugin("acceptParser", opts); |
195 | 194 | } |
196 | 195 |
|
197 | 196 | // Date parser |
198 | 197 | dateParser(opts) { |
199 | | - return useRestifyPlugin("dateParser", opts); |
| 198 | + return this.useRestifyPlugin("dateParser", opts); |
200 | 199 | } |
201 | 200 |
|
202 | 201 | // Query parser |
203 | 202 | queryParser(opts) { |
204 | | - return useRestifyPlugin("queryParser", opts); |
| 203 | + return this.useRestifyPlugin("queryParser", opts); |
205 | 204 | } |
206 | 205 |
|
207 | 206 | // JOSN-P |
208 | 207 | jsonp(opts) { |
209 | | - return useRestifyPlugin("jsonp", opts); |
| 208 | + return this.useRestifyPlugin("jsonp", opts); |
210 | 209 | } |
211 | 210 |
|
212 | 211 | // Gzip response |
213 | 212 | gzipResponse(opts) { |
214 | | - return useRestifyPlugin("gzipResponse", opts); |
| 213 | + return this.useRestifyPlugin("gzipResponse", opts); |
215 | 214 | } |
216 | 215 |
|
217 | 216 | // Request expiry |
218 | 217 | requestExpiry(opts) { |
219 | | - return useRestifyPlugin("requestExpiry", opts); |
| 218 | + return this.useRestifyPlugin("requestExpiry", opts); |
220 | 219 | } |
221 | 220 |
|
222 | 221 | // Throttle |
223 | 222 | throttle(opts) { |
224 | | - return useRestifyPlugin("throttle", opts); |
| 223 | + return this.useRestifyPlugin("throttle", opts); |
225 | 224 | } |
226 | 225 |
|
227 | 226 |
|
228 | 227 | // Audit logger |
229 | 228 | auditLogger(opts) { |
230 | | - return useRestifyPlugin("auditLogger", opts); |
| 229 | + return this.useRestifyPlugin("auditLogger", opts); |
231 | 230 | } |
232 | 231 |
|
233 | 232 | // Request logger |
234 | 233 | requestLogger(opts) { |
235 | | - return useRestifyPlugin("requestLogger", opts); |
| 234 | + return this.useRestifyPlugin("requestLogger", opts); |
236 | 235 | } |
237 | 236 |
|
238 | 237 | // Sanitize Path |
239 | 238 | sanitizePath(opts) { |
240 | | - return useRestifyPlugin("sanitizePath", opts); |
| 239 | + return this.useRestifyPlugin("sanitizePath", opts); |
241 | 240 | } |
242 | 241 |
|
243 | 242 | // Serve Static |
244 | 243 | serveStatic(opts) { |
245 | | - return useRestifyPlugin("serveStatic", opts); |
| 244 | + return this.useRestifyPlugin("serveStatic", opts); |
246 | 245 | } |
247 | 246 |
|
248 | 247 | // Full Response |
249 | 248 | fullResponse(opts) { |
250 | | - return useRestifyPlugin("fullResponse", opts); |
| 249 | + return this.useRestifyPlugin("fullResponse", opts); |
251 | 250 | } |
252 | 251 |
|
253 | 252 | // JSON Body Parser |
254 | 253 | jsonBodyParser(opts) { |
255 | | - return useRestifyPlugin("jsonBodyParser", opts); |
| 254 | + return this.useRestifyPlugin("jsonBodyParser", opts); |
256 | 255 | } |
257 | 256 |
|
258 | 257 |
|
259 | 258 | // Multipart Body Parser |
260 | 259 | multipartBodyParser(opts) { |
261 | | - return useRestifyPlugin("multipartBodyParser", opts); |
| 260 | + return this.useRestifyPlugin("multipartBodyParser", opts); |
262 | 261 | } |
263 | 262 |
|
264 | 263 | // Url Encoded Body Parser |
265 | 264 | urlEncodedBodyParser(opts) { |
266 | | - return useRestifyPlugin("urlEncodedBodyParser", opts); |
| 265 | + return this.useRestifyPlugin("urlEncodedBodyParser", opts); |
267 | 266 | } |
268 | 267 |
|
269 | 268 | // Conditional request |
270 | 269 | conditionalRequest(opts) { |
271 | | - return useRestifyPlugin("conditionalRequest", opts); |
| 270 | + return this.useRestifyPlugin("conditionalRequest", opts); |
| 271 | + } |
| 272 | + |
| 273 | + useRestifyPlugin(plugin, options) { |
| 274 | + var skipTLS; |
| 275 | + options = options || { |
| 276 | + enabled: false |
| 277 | + }; |
| 278 | + skipTLS = plugin === "gzipResponse"; |
| 279 | + if (options.enabled) { |
| 280 | + return this.server("use", RESTIFY[plugin](options.settings), skipTLS); |
| 281 | + } |
272 | 282 | } |
273 | 283 |
|
274 | 284 |
|
|
323 | 333 | // Extend PluginHelper |
324 | 334 | API.extend(PluginHelper); |
325 | 335 |
|
326 | | - |
327 | 336 | //####### API Internal Functions ######## |
328 | | - useRestifyPlugin = function(plugin, options) { |
329 | | - var skipTLS; |
330 | | - options = options || { |
331 | | - enabled: false |
332 | | - }; |
333 | | - skipTLS = plugin === "gzipResponse"; |
334 | | - if (indexOf.call(RESTIFY, plugin) >= 0 && options.enabled) { |
335 | | - return this.server("use", RESTIFY[plugin](options.settings), skipTLS); |
336 | | - } |
337 | | - }; |
338 | 337 |
|
339 | 338 | // Response wrapper |
340 | 339 | _response = function(req, res, next, data) { |
|
0 commit comments