From d668d43a0a40a58975cb99d5da622a352cfb4c2f Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 15 Jul 2015 22:43:24 +0100 Subject: [PATCH] Move to express 4.x --- nodes/core/core/20-inject.js | 6 ++-- nodes/core/core/58-debug.js | 8 ++--- nodes/core/io/21-httpin.js | 36 +++++++++-------------- package.json | 3 +- red/api/auth/index.js | 4 +-- red/api/flows.js | 4 +-- red/api/index.js | 7 +++-- red/api/library.js | 28 +++++++++--------- red/api/locales.js | 2 +- red/api/nodes.js | 52 ++++++++++++++++----------------- red/api/theme.js | 32 ++++++++++---------- red/api/ui.js | 10 +++---- red/i18n.js | 2 +- test/red/api/auth/index_spec.js | 20 ++++++------- test/red/api/flows_spec.js | 11 +++---- test/red/api/library_spec.js | 37 +++++++++++------------ test/red/api/nodes_spec.js | 3 +- test/red/api/ui_spec.js | 26 ++++++++--------- 18 files changed, 143 insertions(+), 148 deletions(-) diff --git a/nodes/core/core/20-inject.js b/nodes/core/core/20-inject.js index b7daac709..f97bf6fb5 100644 --- a/nodes/core/core/20-inject.js +++ b/nodes/core/core/20-inject.js @@ -81,13 +81,13 @@ module.exports = function(RED) { if (node != null) { try { node.receive(); - res.send(200); + res.sendStatus(200); } catch(err) { - res.send(500); + res.sendStatus(500); node.error(RED._("inject.failed",{error:err.toString()})); } } else { - res.send(404); + res.sendStatus(404); } }); } diff --git a/nodes/core/core/58-debug.js b/nodes/core/core/58-debug.js index 8068cf736..43e030f59 100644 --- a/nodes/core/core/58-debug.js +++ b/nodes/core/core/58-debug.js @@ -142,15 +142,15 @@ module.exports = function(RED) { if (node !== null && typeof node !== "undefined" ) { if (state === "enable") { node.active = true; - res.send(200); + res.sendStatus(200); } else if (state === "disable") { node.active = false; - res.send(201); + res.sendStatus(201); } else { - res.send(404); + res.sendStatus(404); } } else { - res.send(404); + res.sendStatus(404); } }); }; diff --git a/nodes/core/io/21-httpin.js b/nodes/core/io/21-httpin.js index d192af453..a83fb55eb 100644 --- a/nodes/core/io/21-httpin.js +++ b/nodes/core/io/21-httpin.js @@ -19,13 +19,13 @@ module.exports = function(RED) { var http = require("follow-redirects").http; var https = require("follow-redirects").https; var urllib = require("url"); - var express = require("express"); + var bodyParser = require("body-parser"); var getBody = require('raw-body'); var mustache = require("mustache"); var querystring = require("querystring"); var cors = require('cors'); - var jsonParser = express.json(); - var urlencParser = express.urlencoded(); + var jsonParser = bodyParser.json(); + var urlencParser = bodyParser.urlencoded({extended:true}); var onHeaders = require('on-headers'); function rawBodyParser(req, res, next) { @@ -43,6 +43,7 @@ module.exports = function(RED) { }); } + var corsSetup = false; function HTTPIn(n) { RED.nodes.createNode(this,n); @@ -60,7 +61,7 @@ module.exports = function(RED) { this.errorHandler = function(err,req,res,next) { node.warn(err); - res.send(500); + res.sendStatus(500); }; this.callback = function(req,res) { @@ -77,9 +78,10 @@ module.exports = function(RED) { var corsHandler = function(req,res,next) { next(); } - if (RED.settings.httpNodeCors) { + if (RED.settings.httpNodeCors && !corsSetup) { corsHandler = cors(RED.settings.httpNodeCors); - RED.httpNode.options(this.url,corsHandler); + RED.httpNode.options("*",corsHandler); + corsSetup = true; } var httpMiddleware = function(req,res,next) { next(); } @@ -121,24 +123,12 @@ module.exports = function(RED) { } this.on("close",function() { - var routes = RED.httpNode.routes[this.method]; - for (var i = 0; i",file); app.get(url,function(req, res) { - res.sendfile(file); + res.sendFile(file); }); return "theme"+url; } catch(err) { @@ -58,13 +58,13 @@ module.exports = { var url; themeContext = clone(defaultContext); themeSettings = null; - + if (settings.editorTheme) { var theme = settings.editorTheme; themeSettings = {}; - + var themeApp = express(); - + if (theme.page) { if (theme.page.css) { var styles = theme.page.css; @@ -72,7 +72,7 @@ module.exports = { styles = [styles]; } themeContext.page.css = []; - + for (i=0;i