Skip to content

Commit

Permalink
Check mod_rewrite is enabled server side before starting chat
Browse files Browse the repository at this point in the history
  • Loading branch information
kerphi committed Dec 8, 2012
1 parent 609266b commit 586381f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
64 changes: 49 additions & 15 deletions client/jquery.phpfreechat.init.js
Expand Up @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions server/routes/utils.php
Expand Up @@ -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.