I use koa.js and there is a problem: how can I make the system render a new template or just redirect when receiving post data?
Several times I tried to do something like this, but nothing happens. I can not understand why.
var server = require('koa')(), path = require('path'), projectRoot = __dirname, staticRoot = path.join(projectRoot, '../public'), templateRoot = path.join(projectRoot, '/engine/template'), koaviews = require('koa-views')(templateRoot, {default : 'swig'}), body = require('koa-better-body'), router = require('koa-router')(); server.use(require('koa-static')(staticRoot)); server.use(koaviews); server.use(body({ multipart: true })); router.get('/', function *(next) { console.log('GET'); yield this.render('terminal/testlogin'); }); router.post('/', function *(next) { console.log('POST'); yield this.render('terminal/terminal'); }); server.use(router.routes()); /*server.use(function *() { this.status = 404; yield this.render('service/404'); });*/ server.listen(80); console.log('Сервер запустился. Порт - 80'); get works successfully - the form is displayed, but on post data when sending from a form, I get only an entry in the console and that's it. The page does not change.
Also tried to do this:
router.post('/', function *(next) { console.log('POST'); this.redirect('/sign-in'); this.status = 301; }); Nothing too. When trying to pass on through yield
yield this.redirect('/sign-in'); I get notified that only generators or promises can be transmitted.