mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
In response to hwillson's feedback, added test to webapp_tests for socketPath and made cosmetic fixes to UNIX socket code to conform better with meteor's coding style.
This commit is contained in:
@@ -817,65 +817,46 @@ var runWebAppServer = function () {
|
||||
var host = process.env.BIND_IP;
|
||||
var localIp = host || '0.0.0.0';
|
||||
|
||||
if (typeof localPort == "number")
|
||||
{
|
||||
var startHttpServer = function(listenOptions) {
|
||||
httpServer.listen(listenOptions, Meteor.bindEnvironment(function() {
|
||||
if (process.env.METEOR_PRINT_ON_LISTEN)
|
||||
console.log("LISTENING"); // must match run-app.js
|
||||
|
||||
var callbacks = onListeningCallbacks;
|
||||
onListeningCallbacks = null;
|
||||
_.each(callbacks, function (x) { x(); });
|
||||
|
||||
}, function (e) {
|
||||
console.error("Error listening:", e);
|
||||
console.error(e && e.stack);
|
||||
}));
|
||||
};
|
||||
|
||||
if (typeof localPort == "number") {
|
||||
var listenOptions = { port: localPort, host: host };
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
var socketPath = localPort;
|
||||
var listenOptions = { path: socketPath };
|
||||
|
||||
httpServer.on('error', Meteor.bindEnvironment(function(e) {
|
||||
|
||||
if (e.code == 'EADDRINUSE') {
|
||||
|
||||
var clientSocket = new net.Socket();
|
||||
|
||||
clientSocket.on('error', Meteor.bindEnvironment(function(e) {
|
||||
|
||||
if (e.code == 'ECONNREFUSED') {
|
||||
|
||||
console.log("Deleting stale socket file");
|
||||
fs.unlinkSync(socketPath);
|
||||
|
||||
httpServer.listen(listenOptions, Meteor.bindEnvironment(function() {
|
||||
if (process.env.METEOR_PRINT_ON_LISTEN)
|
||||
console.log("LISTENING"); // must match run-app.js
|
||||
|
||||
var callbacks = onListeningCallbacks;
|
||||
onListeningCallbacks = null;
|
||||
_.each(callbacks, function (x) { x(); });
|
||||
|
||||
}, function (e) {
|
||||
console.error("Error listening:", e);
|
||||
console.error(e && e.stack);
|
||||
}));
|
||||
|
||||
startHttpServer(listenOptions);
|
||||
}
|
||||
}));
|
||||
|
||||
clientSocket.connect({ path: socketPath }, function() {
|
||||
console.log("Another server is already listening on socket: " + socketPath + ", exiting.");
|
||||
process.exit();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
httpServer.listen(listenOptions, Meteor.bindEnvironment(function() {
|
||||
if (process.env.METEOR_PRINT_ON_LISTEN)
|
||||
console.log("LISTENING"); // must match run-app.js
|
||||
|
||||
var callbacks = onListeningCallbacks;
|
||||
onListeningCallbacks = null;
|
||||
_.each(callbacks, function (x) { x(); });
|
||||
|
||||
}, function (e) {
|
||||
console.error("Error listening:", e);
|
||||
console.error(e && e.stack);
|
||||
}));
|
||||
startHttpServer(listenOptions);
|
||||
|
||||
return 'DAEMON';
|
||||
};
|
||||
|
||||
@@ -157,15 +157,18 @@ Tinytest.add("webapp - generating boilerplate should not change runtime config",
|
||||
});
|
||||
|
||||
// Support 'named pipes' (strings) as ports for support of Windows Server / Azure deployments
|
||||
Tinytest.add("webapp - port should be parsed as int unless it is a named pipe", function(test){
|
||||
Tinytest.add("webapp - port should be parsed as int unless it is a named pipe or path/filename of a Unix domain socket", function(test){
|
||||
// Named pipes on Windows Server follow the format: \\.\pipe\{randomstring} or \\{servername}\pipe\{randomstring}
|
||||
var namedPipe = "\\\\.\\pipe\\b27429e9-61e3-4c12-8bfe-950fa3295f74";
|
||||
var namedPipeServer = "\\\\SERVERNAME-1234\\pipe\\6e157e98-faef-49e4-a0cf-241037223308";
|
||||
var socketPath = "/var/run/meteor.sock";
|
||||
|
||||
test.equal(WebAppInternals.parsePort(namedPipe),
|
||||
"\\\\.\\pipe\\b27429e9-61e3-4c12-8bfe-950fa3295f74");
|
||||
test.equal(WebAppInternals.parsePort(namedPipeServer),
|
||||
"\\\\SERVERNAME-1234\\pipe\\6e157e98-faef-49e4-a0cf-241037223308");
|
||||
test.equal(WebAppInternals.parsePort(socketPath),
|
||||
"/var/run/meteor.sock");
|
||||
test.equal(WebAppInternals.parsePort(8080),
|
||||
8080);
|
||||
test.equal(WebAppInternals.parsePort("8080"),
|
||||
|
||||
Reference in New Issue
Block a user