• koa 第一课


    var mount = require('koa-mount');//用于路由
    var koa = require('koa');
    var views = require('koa-views');//用于界面渲染
    
    // hello.html
      var kk = require('koa');
       var aa = kk();
        aa.use(function *(next){
            yield  this.render('./hello');
        });
    module.exports  = aa
    
    //hello.js文件可以逻辑分离出来的
    var a = koa();
    a.use(function *(next){
        yield  this.render('./hello');
    });
    
    // world.html
    var b = koa();
    b.use(function *(next){
        yield  this.render('./world')
    });
    //basic.html
    var c = koa();
    c.use(function *(next){
        yield  this.render('./basic')
    });
    
    var app = module.exports=koa();//module.exports暂时的理解就是如果写了这个那么别的js导入的时候就是这个对象
     app.use(function *PageNotFound(next){
        yield next;
        if (404 != this.status) return;
        this.status = 404;
        yield  this.render('./notFound')
    })
    app.use(views());
    app.use(mount('/hello', a));
    app.use(mount('/world', b));
    //app.use(mount('/',c)); //不知道为什么这个是通配符(如果打开这个测试不到404)
    app.listen(3000);
    console.log('listening on port 3000');
  • 相关阅读:
    2月24日-寒假进度24
    2月23日-寒假学习进度23
    2月22日-寒假学习进度22
    2月21日-寒假学习进度21
    第一周冲刺意见汇总
    团队绩效评估
    团队工作第七天
    团队工作第六天
    团队工作第五天
    团队工作第四天
  • 原文地址:https://www.cnblogs.com/liyang31tg/p/5055353.html
Copyright © 2020-2023  润新知