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

Commit

Permalink
tiny fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Burnett01 committed Jan 6, 2020
1 parent 6803f27 commit a8e1ea5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@burnett01/sys-api",
"version": "1.1.0",
"version": "1.2.0",
"bugs": {
"url": "https://github.com/Burnett01/sys-api/issues"
},
Expand Down
45 changes: 23 additions & 22 deletions src/API.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -161,85 +161,86 @@ class API extends ClassHelper

# Cross-Origin Resource Sharing
cors: (opts) ->
useRestifyPlugin("CORS", opts)
@useRestifyPlugin("CORS", opts)

# Body parser
bodyParser: (opts) ->
useRestifyPlugin("bodyParser", opts)
@useRestifyPlugin("bodyParser", opts)

# Accept parser
acceptParser: (opts) ->
useRestifyPlugin("acceptParser", opts)
@useRestifyPlugin("acceptParser", opts)

# Date parser
dateParser: (opts) ->
useRestifyPlugin("dateParser", opts)
@useRestifyPlugin("dateParser", opts)

# Query parser
queryParser: (opts) ->
useRestifyPlugin("queryParser", opts)
@useRestifyPlugin("queryParser", opts)

# JOSN-P
jsonp: (opts) ->
useRestifyPlugin("jsonp", opts)
@useRestifyPlugin("jsonp", opts)

# Gzip response
gzipResponse: (opts) ->
useRestifyPlugin("gzipResponse", opts)
@useRestifyPlugin("gzipResponse", opts)

# Request expiry
requestExpiry: (opts) ->
useRestifyPlugin("requestExpiry", opts)
@useRestifyPlugin("requestExpiry", opts)

# Throttle
throttle: (opts) ->
useRestifyPlugin("throttle", opts)
@useRestifyPlugin("throttle", opts)

# Audit logger
auditLogger: (opts) ->
useRestifyPlugin("auditLogger", opts)
@useRestifyPlugin("auditLogger", opts)

# Request logger
requestLogger: (opts) ->
useRestifyPlugin("requestLogger", opts)
@useRestifyPlugin("requestLogger", opts)

# Sanitize Path
sanitizePath: (opts) ->
useRestifyPlugin("sanitizePath", opts)
@useRestifyPlugin("sanitizePath", opts)

# Serve Static
serveStatic: (opts) ->
useRestifyPlugin("serveStatic", opts)
@useRestifyPlugin("serveStatic", opts)

# Full Response
fullResponse: (opts) ->
useRestifyPlugin("fullResponse", opts)
@useRestifyPlugin("fullResponse", opts)

# JSON Body Parser
jsonBodyParser: (opts) ->
useRestifyPlugin("jsonBodyParser", opts)
@useRestifyPlugin("jsonBodyParser", opts)

# Multipart Body Parser
multipartBodyParser: (opts) ->
useRestifyPlugin("multipartBodyParser", opts)
@useRestifyPlugin("multipartBodyParser", opts)

# Url Encoded Body Parser
urlEncodedBodyParser: (opts) ->
useRestifyPlugin("urlEncodedBodyParser", opts)
@useRestifyPlugin("urlEncodedBodyParser", opts)

# Conditional request
conditionalRequest: (opts) ->
useRestifyPlugin("conditionalRequest", opts)
@useRestifyPlugin("conditionalRequest", opts)


######## API Internal Functions ########

useRestifyPlugin = (plugin, options) ->
useRestifyPlugin: (plugin, options) ->
options = options || { enabled: false }
skipTLS = plugin == "gzipResponse"
if plugin in RESTIFY && options.enabled
if options.enabled
@server("use", RESTIFY[plugin](options.settings), skipTLS)


######## API Internal Functions ########

# Response wrapper
_response = (req, res, next, data) ->
res.send({ response: data })
Expand Down
63 changes: 31 additions & 32 deletions src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var API, Addons, BCRYPT, ClassHelper, MORGAN, PluginHelper, RESTIFY,
splice = [].splice,
indexOf = [].indexOf;
splice = [].splice;

RESTIFY = require('restify');

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

API = (function() {
var _request, _response, addon, i, index, len, useRestifyPlugin;
var _request, _response, addon, i, index, len;

class API extends ClassHelper {
constructor(options) {
Expand Down Expand Up @@ -181,94 +180,105 @@

// Cross-Origin Resource Sharing
cors(opts) {
return useRestifyPlugin("CORS", opts);
return this.useRestifyPlugin("CORS", opts);
}

// Body parser
bodyParser(opts) {
return useRestifyPlugin("bodyParser", opts);
return this.useRestifyPlugin("bodyParser", opts);
}

// Accept parser
acceptParser(opts) {
return useRestifyPlugin("acceptParser", opts);
return this.useRestifyPlugin("acceptParser", opts);
}

// Date parser
dateParser(opts) {
return useRestifyPlugin("dateParser", opts);
return this.useRestifyPlugin("dateParser", opts);
}

// Query parser
queryParser(opts) {
return useRestifyPlugin("queryParser", opts);
return this.useRestifyPlugin("queryParser", opts);
}

// JOSN-P
jsonp(opts) {
return useRestifyPlugin("jsonp", opts);
return this.useRestifyPlugin("jsonp", opts);
}

// Gzip response
gzipResponse(opts) {
return useRestifyPlugin("gzipResponse", opts);
return this.useRestifyPlugin("gzipResponse", opts);
}

// Request expiry
requestExpiry(opts) {
return useRestifyPlugin("requestExpiry", opts);
return this.useRestifyPlugin("requestExpiry", opts);
}

// Throttle
throttle(opts) {
return useRestifyPlugin("throttle", opts);
return this.useRestifyPlugin("throttle", opts);
}


// Audit logger
auditLogger(opts) {
return useRestifyPlugin("auditLogger", opts);
return this.useRestifyPlugin("auditLogger", opts);
}

// Request logger
requestLogger(opts) {
return useRestifyPlugin("requestLogger", opts);
return this.useRestifyPlugin("requestLogger", opts);
}

// Sanitize Path
sanitizePath(opts) {
return useRestifyPlugin("sanitizePath", opts);
return this.useRestifyPlugin("sanitizePath", opts);
}

// Serve Static
serveStatic(opts) {
return useRestifyPlugin("serveStatic", opts);
return this.useRestifyPlugin("serveStatic", opts);
}

// Full Response
fullResponse(opts) {
return useRestifyPlugin("fullResponse", opts);
return this.useRestifyPlugin("fullResponse", opts);
}

// JSON Body Parser
jsonBodyParser(opts) {
return useRestifyPlugin("jsonBodyParser", opts);
return this.useRestifyPlugin("jsonBodyParser", opts);
}


// Multipart Body Parser
multipartBodyParser(opts) {
return useRestifyPlugin("multipartBodyParser", opts);
return this.useRestifyPlugin("multipartBodyParser", opts);
}

// Url Encoded Body Parser
urlEncodedBodyParser(opts) {
return useRestifyPlugin("urlEncodedBodyParser", opts);
return this.useRestifyPlugin("urlEncodedBodyParser", opts);
}

// Conditional request
conditionalRequest(opts) {
return useRestifyPlugin("conditionalRequest", opts);
return this.useRestifyPlugin("conditionalRequest", opts);
}

useRestifyPlugin(plugin, options) {
var skipTLS;
options = options || {
enabled: false
};
skipTLS = plugin === "gzipResponse";
if (options.enabled) {
return this.server("use", RESTIFY[plugin](options.settings), skipTLS);
}
}


Expand Down Expand Up @@ -323,18 +333,7 @@
// Extend PluginHelper
API.extend(PluginHelper);


//####### API Internal Functions ########
useRestifyPlugin = function(plugin, options) {
var skipTLS;
options = options || {
enabled: false
};
skipTLS = plugin === "gzipResponse";
if (indexOf.call(RESTIFY, plugin) >= 0 && options.enabled) {
return this.server("use", RESTIFY[plugin](options.settings), skipTLS);
}
};

// Response wrapper
_response = function(req, res, next, data) {
Expand Down

0 comments on commit a8e1ea5

Please sign in to comment.