Esempio n. 1
0
$swift.disableLog().init(function (err, app)
{
    if (err)
    {
        throw err;
    }

    var config = $swift.configurator.getConfig();
    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // настройка приложения ////////////////////////////////////////////////////////////////////////////////////////////
    //
    // common
    //
    app.configure(function (){});

    //
    //
    //
    var extendResponse = function(req, res, next){
        res.success = function(data){
            res.json({result: data});
        };
        res.error = function(err){
            res.json({error: err});
        };
        next();
    };
    //
    // production
    //
    app.configure('production', 'test', function ()
    {
        app.use($express.favicon());
        app.use($express.static($path.join(__dirname, 'static')));
        app.use($swift.router.endslash);
//        app.use($express.logger());
        app.use($express.bodyParser({ uploadDir: $path.join(__dirname, config.application.uploadDir) }));
        app.use($express.cookieParser());
        app.use($express.session({
            store:  new $memoryStore( config.application.session.memoryStore ),
            secret: config.application.session.secret,
            maxAge: config.application.session.maxAge,
            cookie: { maxAge: config.application.cookie.maxAge }
        }));
        app.use(extendResponse);
        app.use(app.router);
        app.use(function (req, res, next) { res.send(new Error().status = 404); });
    });
    //
    // development
    //
    app.configure('development', 'prog12', 'prog28', 'user316', function ()
    {
        app.use($express.favicon());
        app.use($express.static($path.join(__dirname, 'static')));
        app.use($swift.router.endslash);
        app.use($express.logger('dev'));
        app.use($express.bodyParser({ uploadDir: $path.join(__dirname, config.application.uploadDir) }));
        app.use($express.cookieParser());
        app.use($express.session({
            store:  new $memoryStore( config.application.session.memoryStore ),
            secret: config.application.session.secret,
            maxAge: config.application.session.maxAge,
            cookie: { maxAge: config.application.cookie.maxAge }
        }));
        app.use(extendResponse);
        app.use(app.router);
        app.use(function (req, res, next) { res.send(new Error().status = 404); });
        app.use($express.errorHandler());
    });
    //
    // настройка приложения ////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // модули //////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    $swift.extra('config', {
        data: $swift.require(':app/config/user.json'),
        save: function(callback){
            $fs.writeFile($path.join(__dirname, 'app', 'config', 'user.json'), JSON.stringify(this.data, null, 4), callback);
            $swift.extra('db').connect();
        }
    });
    $swift.extra('db', {
        config: $swift.extra('config'),
        read: null,
        write: null,
        _connected: {
            read: false,
            write: false
        },
        connect: function(){
            var self = this;
            self.disconnect();
            if ((config.data || {}).server == null) return;
            this.write = $redis.createClient(this.config.data.server.port, this.config.data.server.host, this.config.data.server.options);
            this.write.on('connect', function(){
                self._connected.write = true;
            });
            this.write.on('error', function(err){
                self._connected.write = false;
            });

            this.read = $redis.createClient(this.config.data.server.port, this.config.data.server.host, this.config.data.server.options);
            this.read.on('connect', function(){
                self._connected.read = true;
            });
            this.read.on('error', function(err){
                self._connected.read = false;
            });
        },
        disconnect: function(){
            if (this.write) {
                this.write.end();
                this.write = null;
            }
            if (this.read) {
                this.read.end();
                this.read = null;
            }
        }
    });
    var config = $swift.extra('config');
    if ((config.data || {}).server != null){
        $swift.extra('db').connect();
    }
    $swift.moduleManager
        .loadModule('store')
        .loadModule('frontend')
        .$swift()
        .run(function (err)
        {
            if (err){
                logger.log('error', new errors.S1000(err));
                throw err;
            }
            var config = $swift.configurator.getConfig();
            console.log("View monitor on http://" +  config.swift.server.ip + ":" + config.swift.server.port);
        })
    ;
    //
    // модули //////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
});
Esempio n. 2
0
 save: function(callback){
     $fs.writeFile($path.join(__dirname, 'app', 'config', 'user.json'), JSON.stringify(this.data, null, 4), callback);
     $swift.extra('db').connect();
 }
Esempio n. 3
0
$swift/*.disableLog()*/.init(function (err, app)
{
    if (err)
    {
        console.log(err);
        return;
    }

    //
    // настройка приложения
    //

    app.configure(function ()
    {
        app.set('view engine', 'swig');

        app.use($express.favicon());
        app.use($express.static($path.join(__dirname, 'public')));
    });

    app.configure('production', 'test', function ()
    {
        app.use($express.logger());
        app.use($express.bodyParser());
        app.use($swift.router.endslash);
        app.use(app.router);
        app.use(function (req, res) { throw new Error().status = 404; });
    });

    app.configure('development', function ()
    {
        app.use($express.logger('dev'));
        app.use($express.bodyParser());
        app.use($swift.router.endslash);
        app.use(app.router);
        app.use(function (req, res) { throw new Error().status = 404; });
        app.use($express.errorHandler());
    });

    //
    // swig
    //

    app.engine('.swig', $consolidate.swig);

    $swig.init({
        root: $swift.configurator.getConfig().swift.path.app + '/view',
        allowErrors: true
    });

    //
    // подключение модулей
    //

    $swift.moduleManager
        .loadModule('index')
        .$swift()
        .run(function (err) { if (err) console.log(err); console.log('Поехали!'); })
    ;
});
Esempio n. 4
0
    $fs = require('fs'),

    $swift = require('swift.mvc'),

    $express = $swift.express,
    $memoryStore = $express.session.MemoryStore,

    $redis = require('redis');

var errors = require('./app/helpers/errors'),
    logger = require('./app/helpers/logger');

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// swift ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
$swift.disableLog().init(function (err, app)
{
    if (err)
    {
        throw err;
    }

    var config = $swift.configurator.getConfig();
    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // настройка приложения ////////////////////////////////////////////////////////////////////////////////////////////
    //
    // common
    //
    app.configure(function (){});
Esempio n. 5
0
/**
 * Powered by Andy <*****@*****.**>
 * Date: 28.08.13
 */

var $swift = require('swift.mvc'),
    errors = $swift.require(':app/helpers/errors'),
    config = $swift.extra('config'),
    uuid = require('uuid');

exports.get = function(callback){
    callback(null, config.data.blocks || []);
};

exports.set = function(id, data, callback){
    data.id = id;
    if (config.data.blocks == null) config.data.blocks = [];
    for(var i = 0; i < config.data.blocks.length; i++){
        if (config.data.blocks[i].id === id){
            config.data.blocks[i] = data;
            config.save(function(err){
                callback(err, data);
            });
            return;
        }
    }
};

exports.create = function(data, callback){
    data.id = uuid.v4();
    if (config.data.blocks == null) config.data.blocks = [];