作家
登录

微信小程序架构分析 (下)

作者: 来源: 2017-06-09 13:47:09 阅读 我要评论

</head> 
  • <body> 
  •   <script> 
  •     window._____sendMsgToNW({ 
  •       sdkName: 'APP_SERVICE_COMPLETE' 
  •     }) 
  •   </script> 
  • </body> 
  • view.html:

    第二步: 实现 http 办事

    server.js

    1. // 日记中心件 
    2. app.use(logger()) 
    3. // gzip 
    4. app.use(compress({ 
    5.   threshold: 2048, 
    6.   flush: require('zlib').Z_SYNC_FLUSH 
    7. })) 
    8. // 缺点提示中心件 
    9. app.use(notifyError) 
    10. // 应用当前目次下文件处理 404 请求 
    11. app.use(staticFallback) 
    12. // 各类 route 实现 
    13. app.use(router.routes()) 
    14. app.use(router.allowedMethods()) 
    15. // 对于 public 目次启用静态文件办事 
    16. app.use(require('koa-static')(path.resolve(__dirname, '../public'))) 
    17. // 创建启动办事 
    18. let server = http.createServer(app.callback()) 
    19. server.listen(3000)  

    router.js

    1. router.get('/'function *() { 
    2.   // 加载 index.html 模板和数据,输出 index 页面 
    3. }) 
    4.  
    5. router.get('/appservice'function *() { 
    6.   // 加载 service.html 模板和数据,输出 service 页面 
    7. }) 
    8.  
    9. // 让 `/app/**` 加载小法度榜样地点目次文件 
    10. router.get('/app/(.*)'function* () { 
    11.   if (/\.(wxss|js)$/.test(file)) { 
    12.     // 动态编译为 css 和响应 js 
    13.   } else if (/\.wxml/.test(file)) { 
    14.     // 动态编译为 html 
    15.   } else { 
    16.     // 查找其它类型文件, 存在则返回 
    17.     let exists = util.exists(file) 
    18.     if (exists) { 
    19.       yield send(this, file) 
    20.     } else { 
    21.       this.status = 404 
    22.       throw new Error(`File: ${file} not found`) 
    23.     } 
    24.   } 
    25. })  

    第三步:实现控制层功能

    1. <head> 
    2.   <link href=http://developer.51cto.com/art/201706/"https://res.wx.qq.com/mpres/htmledition/images/favicon218877.ico"

        推荐阅读

        CIO半月刊第十二期|打造“智慧交通”,保障城市高效、安全、智能化运行

      【义务编辑:谢海平 TEL:(010)68476606】 >>>详细阅读


      本文标题:微信小程序架构分析 (下)

      地址:http://www.17bianji.com/lsqh/35676.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)