Permalink
Browse files

Check mod_rewrite is enabled server side before starting chat

  • Loading branch information...
kerphi committed Dec 8, 2012
1 parent 609266b commit 586381f358501e30e82e1d8a69fda2b61183f3ae
Showing with 60 additions and 15 deletions.
  1. +49 −15 client/jquery.phpfreechat.init.js
  2. +11 −0 server/routes/utils.php
@@ -31,27 +31,61 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
pfc.loadHTML();
pfc.loadResponsiveBehavior();
// run quick tests
pfc.checkServerConfig(pfc.startChatLogic);
}
/**
* Run few tests to be sure the server is ready to receive requests
*/
pfc.checkServerConfig = function (next) {
if (pfc.options.check_server_config) {
$.ajax({
type: 'GET',
url: pfc.options.serverCheckUrl
}).done(function (errors) {
if (errors && errors.length > 0) {
pfc.showErrorsPopup(errors);
} else {
pfc.startChatLogic();
}
}).error(function () {
pfc.showErrorsPopup([ 'Unknown error' ]);
pfc.checkServerConfigPHP(function () {
pfc.checkServerConfigRewrite(next);
});
} else {
pfc.startChatLogic();
next();
}
};
}
/**
* Test the server php config file
*/
pfc.checkServerConfigPHP = function (next) {
$.ajax({
type: 'GET',
url: pfc.options.serverCheckUrl
}).done(function (errors) {
if (errors && errors.length > 0) {
pfc.showErrorsPopup(errors);
} else {
next();
}
}).error(function () {
pfc.showErrorsPopup([ 'Unknown error: check.php cannot be found' ]);
});
};
/**
* Test the rewrite rules are enabled on the server
*/
pfc.checkServerConfigRewrite = function (next) {
$.ajax({
type: 'GET',
url: pfc.options.serverUrl + '/status'
}).done(function (status) {
if (!status || !status.running) {
pfc.showErrorsPopup([ 'mod_rewrite must be enabled server side' ]);
} else {
next();
}
}).error(function () {
pfc.showErrorsPopup([ 'mod_rewrite must be enabled server side' ]);
});
};
/**
* Start to authenticate and to prepare chat dynamic
*/
View
@@ -22,3 +22,14 @@
$res->status(@touch($si_file) ? 200 : 500);
});
/**
* Route used to know if rewriting rules are enable in the web server
*/
$app->get('/status', function () use ($app, $req, $res) {
$res->status(200);
$res['Content-Type'] = 'application/json; charset=utf-8';
$res->body('{ "running": true }');
});

0 comments on commit 586381f

Please sign in to comment.