Skip to content

Commit

Permalink
fixed the debug mode for Silex server
Browse files Browse the repository at this point in the history
  • Loading branch information
lexoyo committed Aug 3, 2015
1 parent 46cc7ca commit b4b7fae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 44 deletions.
57 changes: 19 additions & 38 deletions dist/server/server.js
Expand Up @@ -62,9 +62,8 @@ app.use('/', session({
}));

// ********************************
// production
// production / debug
// ********************************
var isDebug = false;
/**
* catch all errors to prevent nodejs server crash
*/
Expand All @@ -73,29 +72,23 @@ function onCatchError(err) {
console.error('---------------------', 'Caught exception: ', err, '---------------------');
console.log('---------------------');
}
/**
* set debug or production modes
*/
exports.setDebugMode = function(debug){
if(debug && !isDebug){
process.removeListener('uncaughtException', onCatchError);

// DEBUG ONLY
console.warn('Running server in debug mode');
// define users (login/password) wich will be authorized to access the www folder (read and write)
silexConfig.www.USERS = {
'admin': 'admin'
};
}
if(!debug && isDebug){
// PRODUCTION ONLY
console.warn('Running server in production mode');
// catch all errors and prevent nodejs to crash, production mode
process.on('uncaughtException', onCatchError);
// reset debug
silexConfig.www.USERS = {};
}
};
if(process.env.SILEX_DEBUG) {
// DEBUG ONLY
console.warn('Running server in debug mode');
// define users (login/password) wich will be authorized to access the www folder (read and write)
silexConfig.www.USERS = {
'admin': 'admin'
};
}
else {
// PRODUCTION ONLY
console.warn('Running server in production mode');
// catch all errors and prevent nodejs to crash, production mode
process.on('uncaughtException', onCatchError);
// reset debug
silexConfig.www.USERS = {};
}

// ********************************
// config
// ********************************
Expand All @@ -114,25 +107,13 @@ silexConfig.staticFolders.push(
name: '/js/src',
path: pathModule.resolve(__dirname, '../../src')
},
// when working offline, you can re-route http://static.silex.me/ to http://localhost:6805/static/
// the scripts which have to be available in all versions (v2.1, v2.2, v2.3, ...)
{
name: '/static',
path: pathModule.resolve(__dirname, '../../static.silex.me')
}
);

// get command line args
var debug = false;
for (var i in process.argv){
var val = process.argv[i];
if (val === '-debug') {
debug = true;
}
}

// debug or production mode
exports.setDebugMode(debug);

// ********************************
// unifile server
// ********************************
Expand Down
3 changes: 0 additions & 3 deletions docs/dev-notes.md
@@ -1,8 +1,5 @@
## Silex next steps, TOC

push lexoyo/master to silexlabs/develop
push build & build-merged branch

a mettre sous forme d'issues et de propositions?

- bugs
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"start": "node dist/server/server.js",
"start:debug": "SILEX_DEBUG=true node dist/server/server.js",
"build": "npm run build:css && npm run build:html && npm run build:js:release ",
"build:css": "node_modules/.bin/lessc src/css/_styles.less dist/client/css/admin.css --clean-css=\"--advanced\" --source-map",
"build:html": "node_modules/.bin/jade src/html/index.jade --out dist/client/ --no-debug",
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Expand Up @@ -119,11 +119,11 @@ Start Silex:

If you develop or debug Silex, these npm scripts can be used with npm (they are defined in the file [package.json](./package.json))

* `$ npm run start` will start the server
* `$ npm run build` will build the client side of Silex (html, css and js), ready for production
* `$ npm start` will start the server
* `$ npm run start:debug` will start the server in debug mode (no error catchall, enable local service to use local file system as a storage)
* `$ npm run build` will build the client side code (html, css, js), ready for production
* `$ npm run build:server` this only check that the server scripts are correct
* `$ npm run watch:client` will watch the html, js and css source folders and rebuild when a file changes
* `$ npm run watch:server` will watch the server source folder and rebuild when a file changes

##dependencies

Expand Down

0 comments on commit b4b7fae

Please sign in to comment.