hi-nginx-1.7.8 釋出,嵌入duktape引擎,支援js開發
阿新 • • 發佈:2018-12-26
hi-nginx-1.7.8釋出了。
這一次更新的重點嵌入javascript引擎duktape,因而支援使用js進行web應用開發。通過以下四個命令開啟duktape支援:
hi_duktape_package_path 配置js檔案模組搜尋路徑(js模組寫法與nodejs一致)
hi_duktape_package_cpath 配置動態庫模組搜尋路徑(動態庫模組基於duktape c介面,但可以同時支援c++)
hi_duktape_content 執行js內容塊
hi_duktape_script 執行js檔案
duktape web開發的介面與python和lua保持一致。例子:
/* var foo = require('foo') hi_res.header('Content-Type','text/plain;charset=UTF-8') hi_res.content(foo.hello()) hi_res.status(200) */ /* var mustache = require('mustache') var template = '<h1>Test mustache engine</h1><p>{{body}}</p>'; var model = {body:'Hello World'}; hi_res.content(mustache.to_html(template,model)) hi_res.status(200) */ /* var handlebars = require('handlebars') var template = handlebars.compile('<h1>Test handlebars engine</h1><p>{{body}}</p>') var model = {body:'Hello World'}; hi_res.content(template(model)) hi_res.status(200) */ /* var echo = require('echo') var t=new echo() t.set('HELLO, ') hi_res.content(t.concat('Tom')) hi_res.status(200) */ /* var route = require('route').get_instance() route.get('^\/get/?(\\w+)$', function (req, res, param) { res.header('Content-Type', 'text/plain;charset=UTF8') res.content(req.method()+'\n'+req.uri() + '\n' + param.toString()) res.status(200) }) route.post('^\/post/?([a-zA-Z]+)?$', function (req, res, param) { res.header('Content-Type', 'text/plain;charset=UTF8') res.content(req.method()+'\n'+req.uri() + '\n' + param.toString()) res.status(200) }) route.put('^\/put/?([0-9]+)?', function (req, res, param) { res.header('Content-Type', 'text/plain;charset=UTF8') res.content(req.method()+'\n'+req.uri() + '\n' + param.toString()) res.status(200) }) route.add(['GET', 'POST', 'PUT'], '^\/(.*)$', function (req, res, param) { res.header('Content-Type', 'text/plain;charset=UTF8') res.content(req.method()+'\n'+req.uri() + '\n' + param.toString()) res.status(200) }) route.run(hi_req, hi_res) */ /* var loaded = hi_module.require('demo', 'cpp') var registered = cpp() if (loaded && registered) { var a = new demo() hi_res.header('Content-Type', 'text/plain;charset=UTF-8') hi_res.content(a.echo('hello,cpp class')) hi_res.status(200) hi_module.free(a) } */ ///* hi_res.header('Content-Type','text/plain;charset=UTF-8') hi_res.content('hello,world') hi_res.status(200) //*/