Пример #1
0
// HTTP compression
app.use(compress({}));


// parse request body into ctx.request.body
app.use(body());


// session for passport login, flash messages
app.keys = ['koa-sample-app'];
app.use(session(app));


// MySQL connection pool TODO: how to catch connection exception eg invalid password?
const config = require('./config/db-'+app.env+'.json');
GLOBAL.connectionPool = mysql.createPool(config.db); // put in GLOBAL to pass to sub-apps


// select sub-app (admin/api) according to host subdomain (could also be by analysing request.url);
app.use(function* subApp(next) {
    // use subdomain to determine which app to serve: www. as default, or admin. or api
    const subapp = this.hostname.split('.')[0]; // subdomain = part before first '.' of hostname

    switch (subapp) {
        case 'admin':
            yield compose(require('./apps/admin/app-admin.js').middleware);
            break;
        case 'api':
            yield compose(require('./apps/api/app-api.js').middleware);
            break;
        case 'www':
Пример #2
0
    if (this.hostname.slice(0,3) != 'www') this.response.set('X-Robots-Tag', 'noindex, nofollow');
});


// parse request body into ctx.request.body
app.use(body());


// session for passport login, flash messages
app.keys = ['koa-sample-app'];
app.use(session(app));


// MySQL connection pool TODO: how to catch connection exception eg invalid password?
const config = require('./config/db-'+app.env+'.json');
global.connectionPool = mysql.createPool(config.db); // put in global to pass to sub-apps


// select sub-app (admin/api) according to host subdomain (could also be by analysing request.url);
app.use(function* subApp(next) {
    /* eslint no-unused-vars:off *//* retain the 'next' signature */
    // use subdomain to determine which app to serve: www. as default, or admin. or api
    const subapp = this.hostname.split('.')[0]; // subdomain = part before first '.' of hostname

    switch (subapp) {
        case 'admin':
            yield compose(require('./apps/admin/app-admin.js').middleware);
            break;
        case 'api':
            yield compose(require('./apps/api/app-api.js').middleware);
            break;
Пример #3
0
const parse = require('co-body');

const app = module.exports = koa();
csrf(app);
app.use(session(app));
app.keys = ['some secret phrase'];
app.use(stat(__dirname + '/public'));
const jade = new Jade({
	viewPath: './views',
	debug: false,
	pretty: true,
	compileDebug: false,
	app: app
});

const Pool = mysql.createPool(config);

app.use(function *(next) {
	this.db = yield Pool.getConnection();
	yield next;
	this.db.release();
});
router.get('/favicon.ico', function* (next) {
	return;
	yield next;
});
router.get('/', function* (next) {
		if (this.session.userID === undefined) {
			this.render('index', {message: 'User not authenticated!'});
		} else {
			let result = yield this.db.query(req.list, [`tasks`, `task_owner`, this.session.userID]);