2
0
Fork 0
tcrud/example/example.js
2017-12-23 22:45:27 +01:00

62 lines
2 KiB
JavaScript

'use strict';
var config = require('./example-config.json');
//var favicon = require('static-favicon');
var cookieParser = require('cookie-parser')
var path = require('path');
var winston = require('winston');
winston.loggers.add('main',config.winston);
var log = winston.loggers.get('main');
var expressWinston = require('express-winston');
var tcrud = require('../lib/node-ff-tcrud');
var fs = require('fs');
// PHASE_1: load extra plugins
//tcrud.setup.pluginLoad(new MyPlugin());
require('./lib/pg-moviedb').load(tcrud);
require('./lib/pg-pagila').load(tcrud);
// PHASE_2: enable plugins
tcrud.setup.pluginEnableAll();
// PHASE_3: start config
tcrud.setup.phaseConfig();
tcrud.config.getRootTEntity().tmeta.tplugin.formatXML.tslug = 'xml_is_free';
tcrud.config.getRootTEntity().tmeta.tplugin.formatCSV.tslug = 'csv4all';
var tPostgresDB = tcrud.config.createTEntityNode(tcrud.config.getRootTEntity(),'pg');
var tMongoose = tcrud.config.createTEntityNode(tcrud.config.getRootTEntity(),'mongoose');
require('./lib/pg-moviedb').setup(tcrud,tPostgresDB);
require('./lib/pg-pagila').setup(tcrud,tPostgresDB);
//require('./lib/mongoose-blog').setup(tcrud,tMongoose);
// PHASE_4: finalize config
tcrud.setup.phaseServer();
//tcrud.setup.expressSimple(); or complex;
var server = tcrud.setup.expressCreate();
server.use(expressWinston.logger({
transports: [new winston.transports.Console({json: false,colorize: true})],
meta: false,
expressFormat: true
}));
var buildOptions = {
viewsDir: path.join(__dirname, 'www_views')
}
tcrud.setup.expressBuild(buildOptions);
//server.use(favicon());
server.use(cookieParser(config.options.cookieParser.secretKey));
//server.get('/ui/thtml/*', tcrud.setup.express.renderTemplatePath('thtml/'));
server.use(expressWinston.errorLogger({
transports: [new winston.transports.Console({json: false,colorize: true})]
}));
tcrud.setup.expressListen();
//PHASE_6: post boot to from self.
tcrud.setup.phaseServerUp();