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

Merge branch 'master' of github.com:node-red/node-red

This commit is contained in:
Dave C-J 2013-09-13 23:41:43 +01:00
commit 77eb0f76ce
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 https = require('https');
var util = require("util"); var util = require("util");
var express = require("express"); var express = require("express");
var crypto = require("crypto");
var settings = require("./settings"); 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 server;
var app = express(); var app = express();
settings.httpRoot = settings.httpRoot||""; var redApp = null;
if (settings.httpRoot.slice(-1) == "/") {
settings.httpRoot = settings.httpRoot.slice(0,-1); 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] != "/") { if (settings.httpRoot[0] != "/") {
settings.httpRoot = "/"+settings.httpRoot; settings.httpRoot = "/"+settings.httpRoot;
} }
if (settings.httpRoot == "/") { if (settings.httpRoot.slice(-1) != "/") {
settings.httpRoot = ""; settings.httpRoot = settings.httpRoot + "/";
} }
settings.uiPort = settings.uiPort||1880; settings.uiPort = settings.uiPort||1880;
if (settings.httpAuth) { if (settings.httpAuth) {
app.use(settings.httpRoot, app.use(settings.httpRoot,
express.basicAuth(function(user, pass) { express.basicAuth(function(user, pass) {

View File

@ -21,8 +21,14 @@ var app = express();
function setupUI(settings) { function setupUI(settings) {
app.get(/^$/,function(req,res) { // Need to ensure the url ends with a '/' so the static serving works
res.redirect("/"); // 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')); app.use("/",express.static(__dirname + '/../public'));