2014-01-19 13:37:31 +00:00
|
|
|
/**
|
|
|
|
* TODO license
|
|
|
|
* Bouquins module.
|
|
|
|
*/
|
2014-01-22 17:49:50 +00:00
|
|
|
GLOBAL.PATH_RE=/\/([a-zA-Z0-9]+)(?:\/|$)([a-zA-Z0-9]+)?/;
|
2014-01-19 13:37:31 +00:00
|
|
|
|
2014-01-22 19:20:43 +00:00
|
|
|
var Config = require('./util/config'),
|
2014-01-19 13:37:31 +00:00
|
|
|
logger = require('./util/logger'),
|
|
|
|
Router = require('./router/router'),
|
2014-01-22 19:20:43 +00:00
|
|
|
sqlite3 = require('sqlite3').verbose(),
|
2014-01-19 13:37:31 +00:00
|
|
|
bouquins = exports;
|
|
|
|
|
|
|
|
var router = null;
|
|
|
|
/**
|
|
|
|
* Load config file.
|
|
|
|
*/
|
|
|
|
bouquins.loadconfig = function(configfile, callback) {
|
2014-01-22 19:20:43 +00:00
|
|
|
Config.loadconfig(configfile, callback);
|
2014-01-19 13:37:31 +00:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Init logger.
|
|
|
|
*/
|
|
|
|
bouquins.initLogger = function() {
|
|
|
|
if (config.debugLevel) {
|
|
|
|
logger.debugLevel = config.debugLevel;
|
|
|
|
}
|
|
|
|
return logger;
|
2014-01-22 19:20:43 +00:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Init database.
|
|
|
|
*/
|
|
|
|
bouquins.initDB = function(callback) {
|
|
|
|
logger.debug('Database: '+config.dbfile);
|
|
|
|
GLOBAL.db = new sqlite3.Database(config.dbfile, callback);
|
|
|
|
};
|
2014-01-19 13:37:31 +00:00
|
|
|
/**
|
|
|
|
* Make main router.
|
|
|
|
*/
|
|
|
|
bouquins.makeRouter = function() {
|
|
|
|
if (!router) {
|
|
|
|
router = new Router();
|
|
|
|
}
|
|
|
|
return router;
|
2014-01-22 19:20:43 +00:00
|
|
|
};
|