1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fixes #19 - httpRoot and httpAuth not taking effect

We were attaching the editor app rather than the main app to the
server, which meant the root and auth routes were ignored.
This commit is contained in:
Nicholas O'Leary 2013-09-13 23:22:57 +01:00
parent b0e9dbb929
commit 327ab49622
2 changed files with 22 additions and 18 deletions

30
red.js
View File

@ -17,34 +17,32 @@ var http = require('http');
var https = require('https');
var util = require("util");
var express = require("express");
var crypto = require("crypto");
var settings = require("./settings");
var redApp = null;
if (settings.https) {
server = https.createServer(settings.https,function(req,res){redApp(req,res);});
} else {
server = http.createServer(function(req,res){redApp(req,res);});
}
redApp = require('./red/server.js').init(server,settings);
var server;
var app = express();
settings.httpRoot = settings.httpRoot||"";
if (settings.httpRoot.slice(-1) == "/") {
settings.httpRoot = settings.httpRoot.slice(0,-1);
var redApp = null;
if (settings.https) {
server = https.createServer(settings.https,function(req,res){app(req,res);});
} else {
server = http.createServer(function(req,res){app(req,res);});
}
redApp = require('./red/server.js').init(server,settings);
settings.httpRoot = settings.httpRoot||"/";
if (settings.httpRoot[0] != "/") {
settings.httpRoot = "/"+settings.httpRoot;
}
if (settings.httpRoot == "/") {
settings.httpRoot = "";
if (settings.httpRoot.slice(-1) != "/") {
settings.httpRoot = settings.httpRoot + "/";
}
settings.uiPort = settings.uiPort||1880;
if (settings.httpAuth) {
app.use(settings.httpRoot,
express.basicAuth(function(user, pass) {

View File

@ -21,8 +21,14 @@ var app = express();
function setupUI(settings) {
app.get(/^$/,function(req,res) {
res.redirect("/");
// Need to ensure the url ends with a '/' so the static serving works
// with relative paths
app.get("/",function(req,res) {
if (req.originalUrl.slice(-1) != "/") {
res.redirect(req.originalUrl+"/");
} else {
req.next();
}
});
app.use("/",express.static(__dirname + '/../public'));