From 774b53f2c775c5cc2ff05dc4b1b95437c47d1acd Mon Sep 17 00:00:00 2001 From: wooz Date: Thu, 26 Mar 2020 16:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=81=E8=83=A1=E7=9A=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hu_fw/.vscode/launch.json | 17 +++++++++++ hu_fw/app.js | 62 +++++++++++++++++++++++++++++++++++++++ hu_fw/hello.js | 9 ++++++ hu_fw/test.json | 4 +++ hu_fw/work.js | 25 ++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 hu_fw/.vscode/launch.json create mode 100644 hu_fw/app.js create mode 100644 hu_fw/hello.js create mode 100644 hu_fw/test.json create mode 100644 hu_fw/work.js diff --git a/hu_fw/.vscode/launch.json b/hu_fw/.vscode/launch.json new file mode 100644 index 0000000..d1bb652 --- /dev/null +++ b/hu_fw/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "启动程序", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\app.js" + } + ] +} \ No newline at end of file diff --git a/hu_fw/app.js b/hu_fw/app.js new file mode 100644 index 0000000..d7629a6 --- /dev/null +++ b/hu_fw/app.js @@ -0,0 +1,62 @@ +'use strict'; + +var Koa=require('koa'); + +var router=require('koa-router')(); + +const nunjucks = require('nunjucks'); + +var app=new Koa(); + +function createEnv(path, opts) { + var + autoescape = opts.autoescape === undefined ? true : opts.autoescape, + noCache = opts.noCache || false, + watch = opts.watch || false, + throwOnUndefined = opts.throwOnUndefined || false, + env = new nunjucks.Environment( + new nunjucks.FileSystemLoader('views', { + noCache: noCache, + watch: watch, + }), { + autoescape: autoescape, + throwOnUndefined: throwOnUndefined + }); + if (opts.filters) { + for (var f in opts.filters) { + env.addFilter(f, opts.filters[f]); + } + } + return env; +} + +var env = createEnv('views', { + watch: true, + filters: { + hex: function (n) { + return '0x' + n.toString(16); + } + } +}); + + + +app.use(async (ctx,next)=>{ + console.log(`处理 ${ctx.req.method} ${ctx.req.url}...`); + await next(); +}); + +router.get('/',async (ctx,next)=>{ + ctx.response.body='中华人民共和国'; +}); + +router.get('/hello/:name',async (ctx,next)=>{ + var name=ctx.params.name; + ctx.response.body=`你好呀,${name}`; +}); + +app.use(router.routes()); + +app.listen(3000); + +console.log('程序运行在3000端口'); \ No newline at end of file diff --git a/hu_fw/hello.js b/hu_fw/hello.js new file mode 100644 index 0000000..269effa --- /dev/null +++ b/hu_fw/hello.js @@ -0,0 +1,9 @@ +'use strict'; + +var s = 'Hello'; + +function greet(name) { + console.log(s + ', ' + name + '!'); +} + +module.exports = greet; \ No newline at end of file diff --git a/hu_fw/test.json b/hu_fw/test.json new file mode 100644 index 0000000..a3c1d05 --- /dev/null +++ b/hu_fw/test.json @@ -0,0 +1,4 @@ +{ + "name":"admin", + "password":"123456" +} \ No newline at end of file diff --git a/hu_fw/work.js b/hu_fw/work.js new file mode 100644 index 0000000..34ad728 --- /dev/null +++ b/hu_fw/work.js @@ -0,0 +1,25 @@ +'use strict' + +function test(name,opts){ + var + noCache=opts.noCache ===undefined?true: opts.noCache, + autoescape=opts.autoescape ===undefined ?true:false; + + + if(noCache){ + console.log('选项表示没有缓存'); + + if(opts.noCache){ + console.log('有默认值'); + }else{ + console.log('无默认值'); + } + } +} + +var par={ + abc:true +} + + +test('',par); -- Gitee