Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit a8e1ea5

Browse files
committed
tiny fixes
1 parent 6803f27 commit a8e1ea5

File tree

3 files changed

+55
-55
lines changed

3 files changed

+55
-55
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@burnett01/sys-api",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"bugs": {
55
"url": "https://github.com/Burnett01/sys-api/issues"
66
},

src/API.coffee

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,85 +161,86 @@ class API extends ClassHelper
161161

162162
# Cross-Origin Resource Sharing
163163
cors: (opts) ->
164-
useRestifyPlugin("CORS", opts)
164+
@useRestifyPlugin("CORS", opts)
165165

166166
# Body parser
167167
bodyParser: (opts) ->
168-
useRestifyPlugin("bodyParser", opts)
168+
@useRestifyPlugin("bodyParser", opts)
169169

170170
# Accept parser
171171
acceptParser: (opts) ->
172-
useRestifyPlugin("acceptParser", opts)
172+
@useRestifyPlugin("acceptParser", opts)
173173

174174
# Date parser
175175
dateParser: (opts) ->
176-
useRestifyPlugin("dateParser", opts)
176+
@useRestifyPlugin("dateParser", opts)
177177

178178
# Query parser
179179
queryParser: (opts) ->
180-
useRestifyPlugin("queryParser", opts)
180+
@useRestifyPlugin("queryParser", opts)
181181

182182
# JOSN-P
183183
jsonp: (opts) ->
184-
useRestifyPlugin("jsonp", opts)
184+
@useRestifyPlugin("jsonp", opts)
185185

186186
# Gzip response
187187
gzipResponse: (opts) ->
188-
useRestifyPlugin("gzipResponse", opts)
188+
@useRestifyPlugin("gzipResponse", opts)
189189

190190
# Request expiry
191191
requestExpiry: (opts) ->
192-
useRestifyPlugin("requestExpiry", opts)
192+
@useRestifyPlugin("requestExpiry", opts)
193193

194194
# Throttle
195195
throttle: (opts) ->
196-
useRestifyPlugin("throttle", opts)
196+
@useRestifyPlugin("throttle", opts)
197197

198198
# Audit logger
199199
auditLogger: (opts) ->
200-
useRestifyPlugin("auditLogger", opts)
200+
@useRestifyPlugin("auditLogger", opts)
201201

202202
# Request logger
203203
requestLogger: (opts) ->
204-
useRestifyPlugin("requestLogger", opts)
204+
@useRestifyPlugin("requestLogger", opts)
205205

206206
# Sanitize Path
207207
sanitizePath: (opts) ->
208-
useRestifyPlugin("sanitizePath", opts)
208+
@useRestifyPlugin("sanitizePath", opts)
209209

210210
# Serve Static
211211
serveStatic: (opts) ->
212-
useRestifyPlugin("serveStatic", opts)
212+
@useRestifyPlugin("serveStatic", opts)
213213

214214
# Full Response
215215
fullResponse: (opts) ->
216-
useRestifyPlugin("fullResponse", opts)
216+
@useRestifyPlugin("fullResponse", opts)
217217

218218
# JSON Body Parser
219219
jsonBodyParser: (opts) ->
220-
useRestifyPlugin("jsonBodyParser", opts)
220+
@useRestifyPlugin("jsonBodyParser", opts)
221221

222222
# Multipart Body Parser
223223
multipartBodyParser: (opts) ->
224-
useRestifyPlugin("multipartBodyParser", opts)
224+
@useRestifyPlugin("multipartBodyParser", opts)
225225

226226
# Url Encoded Body Parser
227227
urlEncodedBodyParser: (opts) ->
228-
useRestifyPlugin("urlEncodedBodyParser", opts)
228+
@useRestifyPlugin("urlEncodedBodyParser", opts)
229229

230230
# Conditional request
231231
conditionalRequest: (opts) ->
232-
useRestifyPlugin("conditionalRequest", opts)
232+
@useRestifyPlugin("conditionalRequest", opts)
233233

234-
235-
######## API Internal Functions ########
236234

237-
useRestifyPlugin = (plugin, options) ->
235+
useRestifyPlugin: (plugin, options) ->
238236
options = options || { enabled: false }
239237
skipTLS = plugin == "gzipResponse"
240-
if plugin in RESTIFY && options.enabled
238+
if options.enabled
241239
@server("use", RESTIFY[plugin](options.settings), skipTLS)
242240

241+
242+
######## API Internal Functions ########
243+
243244
# Response wrapper
244245
_response = (req, res, next, data) ->
245246
res.send({ response: data })

src/API.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323
*/
2424
var API, Addons, BCRYPT, ClassHelper, MORGAN, PluginHelper, RESTIFY,
25-
splice = [].splice,
26-
indexOf = [].indexOf;
25+
splice = [].splice;
2726

2827
RESTIFY = require('restify');
2928

@@ -39,7 +38,7 @@
3938
Addons = ["./addons/Fs", "./addons/Os", "./addons/Net"];
4039

4140
API = (function() {
42-
var _request, _response, addon, i, index, len, useRestifyPlugin;
41+
var _request, _response, addon, i, index, len;
4342

4443
class API extends ClassHelper {
4544
constructor(options) {
@@ -181,94 +180,105 @@
181180

182181
// Cross-Origin Resource Sharing
183182
cors(opts) {
184-
return useRestifyPlugin("CORS", opts);
183+
return this.useRestifyPlugin("CORS", opts);
185184
}
186185

187186
// Body parser
188187
bodyParser(opts) {
189-
return useRestifyPlugin("bodyParser", opts);
188+
return this.useRestifyPlugin("bodyParser", opts);
190189
}
191190

192191
// Accept parser
193192
acceptParser(opts) {
194-
return useRestifyPlugin("acceptParser", opts);
193+
return this.useRestifyPlugin("acceptParser", opts);
195194
}
196195

197196
// Date parser
198197
dateParser(opts) {
199-
return useRestifyPlugin("dateParser", opts);
198+
return this.useRestifyPlugin("dateParser", opts);
200199
}
201200

202201
// Query parser
203202
queryParser(opts) {
204-
return useRestifyPlugin("queryParser", opts);
203+
return this.useRestifyPlugin("queryParser", opts);
205204
}
206205

207206
// JOSN-P
208207
jsonp(opts) {
209-
return useRestifyPlugin("jsonp", opts);
208+
return this.useRestifyPlugin("jsonp", opts);
210209
}
211210

212211
// Gzip response
213212
gzipResponse(opts) {
214-
return useRestifyPlugin("gzipResponse", opts);
213+
return this.useRestifyPlugin("gzipResponse", opts);
215214
}
216215

217216
// Request expiry
218217
requestExpiry(opts) {
219-
return useRestifyPlugin("requestExpiry", opts);
218+
return this.useRestifyPlugin("requestExpiry", opts);
220219
}
221220

222221
// Throttle
223222
throttle(opts) {
224-
return useRestifyPlugin("throttle", opts);
223+
return this.useRestifyPlugin("throttle", opts);
225224
}
226225

227226

228227
// Audit logger
229228
auditLogger(opts) {
230-
return useRestifyPlugin("auditLogger", opts);
229+
return this.useRestifyPlugin("auditLogger", opts);
231230
}
232231

233232
// Request logger
234233
requestLogger(opts) {
235-
return useRestifyPlugin("requestLogger", opts);
234+
return this.useRestifyPlugin("requestLogger", opts);
236235
}
237236

238237
// Sanitize Path
239238
sanitizePath(opts) {
240-
return useRestifyPlugin("sanitizePath", opts);
239+
return this.useRestifyPlugin("sanitizePath", opts);
241240
}
242241

243242
// Serve Static
244243
serveStatic(opts) {
245-
return useRestifyPlugin("serveStatic", opts);
244+
return this.useRestifyPlugin("serveStatic", opts);
246245
}
247246

248247
// Full Response
249248
fullResponse(opts) {
250-
return useRestifyPlugin("fullResponse", opts);
249+
return this.useRestifyPlugin("fullResponse", opts);
251250
}
252251

253252
// JSON Body Parser
254253
jsonBodyParser(opts) {
255-
return useRestifyPlugin("jsonBodyParser", opts);
254+
return this.useRestifyPlugin("jsonBodyParser", opts);
256255
}
257256

258257

259258
// Multipart Body Parser
260259
multipartBodyParser(opts) {
261-
return useRestifyPlugin("multipartBodyParser", opts);
260+
return this.useRestifyPlugin("multipartBodyParser", opts);
262261
}
263262

264263
// Url Encoded Body Parser
265264
urlEncodedBodyParser(opts) {
266-
return useRestifyPlugin("urlEncodedBodyParser", opts);
265+
return this.useRestifyPlugin("urlEncodedBodyParser", opts);
267266
}
268267

269268
// Conditional request
270269
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+
}
272282
}
273283

274284

@@ -323,18 +333,7 @@
323333
// Extend PluginHelper
324334
API.extend(PluginHelper);
325335

326-
327336
//####### 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-
};
338337

339338
// Response wrapper
340339
_response = function(req, res, next, data) {

0 commit comments

Comments
 (0)