Skip to content

Commit

Permalink
Fixing support for Windows by conditionally enabling coap & websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Apr 21, 2016
1 parent 3be818e commit 2ba36ab
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 38 deletions.
75 changes: 41 additions & 34 deletions lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ var path = require("path"),
SAMLStrategy = require("passport-saml").Strategy,
TwitterStrategy = require("passport-twitter").Strategy,
RedisStore = require("connect-redis")(session),
lws = require("lws"),
coap = require("coap");
os = require("os");

var lws = void 0,
coap = void 0;

if (os.platform() !== "win32") {
lws = require("lws");
coap = require("coap");
}

function trim(obj) {
return obj.replace(/^(\s+|\t+|\n+)|(\s+|\t+|\n+)$/g, "");
Expand All @@ -44,7 +51,7 @@ function escape(arg) {
function capitalize(obj) {
var all = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];

var result = undefined;
var result = void 0;

if (all) {
result = explode(obj, " ").map(capitalize).join(" ");
Expand Down Expand Up @@ -72,19 +79,19 @@ function auth(obj, config) {
stateful = (async || config.auth.local.enabled || config.security.csrf) !== false,
authMap = {},
authUris = [],
keys = undefined,
sesh = undefined,
fnCookie = undefined,
fnSession = undefined,
luscaCsp = undefined,
luscaCsrf = undefined,
luscaXframe = undefined,
luscaP3p = undefined,
luscaHsts = undefined,
luscaXssProtection = undefined,
passportAuth = undefined,
passportInit = undefined,
passportSession = undefined;
keys = void 0,
sesh = void 0,
fnCookie = void 0,
fnSession = void 0,
luscaCsp = void 0,
luscaCsrf = void 0,
luscaXframe = void 0,
luscaP3p = void 0,
luscaHsts = void 0,
luscaXssProtection = void 0,
passportAuth = void 0,
passportInit = void 0,
passportSession = void 0;

function csrfWrapper(req, res, next) {
if (req.unprotect) {
Expand Down Expand Up @@ -515,16 +522,16 @@ function bootstrap(obj, config) {
config.headers = {};
}

config.headers.server = "tenso/3.3.5";
config.headers.server = "tenso/3.3.6";

// Starting WebSocket server
if (config.websocket.enabled) {
if (config.websocket.enabled && lws) {
obj.websocket = new lws.Server(config.websocket.options);
obj.server.log("Started WebSocket server on port " + config.websocket.options.port, "debug");
}

// Starting COAP server
if (config.coap.enabled) {
if (config.coap.enabled && coap) {
obj.coap = coap.createServer({ type: config.coap.options.type });
obj.coap.listen(config.coap.options.port, config.hostname);
obj.server.log("Started COAP (" + config.coap.options.type + ") server on " + config.hostname + ":" + config.coap.options.port, "debug");
Expand Down Expand Up @@ -597,7 +604,7 @@ function queryString() {

var obj = {};
var aresult = qstring.split("?");
var result = undefined;
var result = void 0;

if (aresult.length > 1) {
aresult.shift();
Expand All @@ -606,7 +613,7 @@ function queryString() {
result = aresult.join("?");
result.split("&").forEach(function (prop) {
var aitem = prop.replace(/\+/g, " ").split("=");
var item = undefined;
var item = void 0;

if (aitem.length > 2) {
item = [aitem.shift(), aitem.join("=")];
Expand Down Expand Up @@ -639,9 +646,9 @@ function queryString() {

function parse(uri) {
var luri = uri;
var idxAscii = undefined,
idxQ = undefined,
parsed = undefined;
var idxAscii = void 0,
idxQ = void 0,
parsed = void 0;

if (luri === undefined || luri === null) {
luri = "";
Expand Down Expand Up @@ -674,26 +681,26 @@ function parse(uri) {
function hypermedia(server, req, rep, headers) {
var seen = {},
collection = req.parsed.pathname,
query = undefined,
page = undefined,
page_size = undefined,
nth = undefined,
root = undefined,
proot = undefined,
parent = undefined;
query = void 0,
page = void 0,
page_size = void 0,
nth = void 0,
root = void 0,
proot = void 0,
parent = void 0;

// Parsing the object for hypermedia properties
function marshal(obj, rel, item_collection) {
var keys = Object.keys(obj),
lrel = rel || "related",
result = undefined;
result = void 0;

if (keys.length === 0) {
result = null;
} else {
array.each(keys, function (i) {
var lcollection = undefined,
uri = undefined;
var lcollection = void 0,
uri = void 0;

// If ID like keys are found, and are not URIs, they are assumed to be root collections
if (regex.id.test(i) || regex.hypermedia.test(i)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tenso",
"description": "Tensō is a REST API gateway for node.js, designed to simplify the implementation of APIs.",
"version": "3.3.5",
"version": "3.3.6",
"homepage": "http://avoidwork.github.io/tenso",
"author": "Jason Mulligan <[email protected]>",
"repository": {
Expand Down
12 changes: 9 additions & 3 deletions src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ const path = require("path"),
SAMLStrategy = require("passport-saml").Strategy,
TwitterStrategy = require("passport-twitter").Strategy,
RedisStore = require("connect-redis")(session),
lws = require("lws"),
os = require("os");

let lws, coap;

if (os.platform() !== "win32") {
lws = require("lws");
coap = require("coap");
}

function trim (obj) {
return obj.replace(/^(\s+|\t+|\n+)|(\s+|\t+|\n+)$/g, "");
Expand Down Expand Up @@ -501,13 +507,13 @@ function bootstrap (obj, config) {
config.headers.server = "tenso/{{VERSION}}";

// Starting WebSocket server
if (config.websocket.enabled) {
if (config.websocket.enabled && lws) {
obj.websocket = new lws.Server(config.websocket.options);
obj.server.log("Started WebSocket server on port " + config.websocket.options.port, "debug");
}

// Starting COAP server
if (config.coap.enabled) {
if (config.coap.enabled && coap) {
obj.coap = coap.createServer({type: config.coap.options.type});
obj.coap.listen(config.coap.options.port, config.hostname);
obj.server.log("Started COAP (" + config.coap.options.type + ") server on " + config.hostname + ":" + config.coap.options.port, "debug");
Expand Down

0 comments on commit 2ba36ab

Please sign in to comment.