view.html:
第二步: 实现 http 办事
server.js
- // 日记中心件
- app.use(logger())
- // gzip
- app.use(compress({
- threshold: 2048,
- flush: require('zlib').Z_SYNC_FLUSH
- }))
- // 缺点提示中心件
- app.use(notifyError)
- // 应用当前目次下文件处理 404 请求
- app.use(staticFallback)
- // 各类 route 实现
- app.use(router.routes())
- app.use(router.allowedMethods())
- // 对于 public 目次启用静态文件办事
- app.use(require('koa-static')(path.resolve(__dirname, '../public')))
- // 创建启动办事
- let server = http.createServer(app.callback())
- server.listen(3000)
router.js
- router.get('/', function *() {
- // 加载 index.html 模板和数据,输出 index 页面
- })
- router.get('/appservice', function *() {
- // 加载 service.html 模板和数据,输出 service 页面
- })
- // 让 `/app/**` 加载小法度榜样地点目次文件
- router.get('/app/(.*)', function* () {
- if (/\.(wxss|js)$/.test(file)) {
- // 动态编译为 css 和响应 js
- } else if (/\.wxml/.test(file)) {
- // 动态编译为 html
- } else {
- // 查找其它类型文件, 存在则返回
- let exists = util.exists(file)
- if (exists) {
- yield send(this, file)
- } else {
- this.status = 404
- throw new Error(`File: ${file} not found`)
- }
- }
- })
第三步:实现控制层功能
- <head>
- <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
1/2 1