多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 1.http服务可用函数列表 | 函数名称 | 参数| 作用 | | --- | --- |--- | | _http_cookie() | (key,[value]) | 获取/设置cookie,value省略表示获取,Set-Cookie:customer=p; path=/foo; domain=.m.com;  expires= Wednesday, 19-OCT-05 23:12:40 GMT; \[secure\] | _http_header() | (key,[value]) | 获取/设置header,value省略表示获取 | _http_params() | (key) | 获取get post请求参数,例如 http_params(‘id’) | _http_redirect() | (url,[code]) | 重定向到某个页面,支持302 304 | _http_tpl() | 无 | 渲染模板输出html (无效,已经删除此函数) | _http_request() | url,path,uri | 查看request请求| | _http_sendfile() | (file_path)| 发送文件| ## 2.用例&说明 **1.)http_cookie** ```lua -- get cookie local cid= http_cookie('cid') --set cllkie http_cookie('cid','123') ``` **2.)http_session** ```lua -- get session local cid= http_session('cid') --set cllkie http_session('cid','123') ``` **3.)http_params** ```lua -- get session -- 用户访问 /?cid=123,post表单中的参数也这么获取 local cid= http_params('cid') -- cid=123 -- 获取上传的文件 avatar local p= http_params('file:avatar') -- p={file='f1.png',size=12336,temp='/temp/t1***'} -- 如果有以下curl请求,那么: --curl --location --request POST 'http://127.0.0.1:8008/api/cloud\_file/upload?sid=5.be847009b7434c949bd18ad460623773' \\ \--form 'folder=/admin' \\ \--form 'size=15548225' \\ \--form 'avatar[]=@/C:/LICENSE.png' \\ \--form 'avatar[]=@/C:/libEGL.png' -- 获取批量上传的文件 avatar[] local p= http_params('file:avatar[]') -- p={{file='f1.png',size=12336,temp='/temp/t1***'},{{file='f2.png',size=12336,temp='/temp/t2***'}}} -- 获取批量参数 local p= http_params('file:avatar[]','name','id') -- p= {['avatar[]']={{file='f1.png',size=12336,temp='/temp/t1***'},{file='f2.png',size=12011,temp='/temp/t2***'}},name='**',id='100'} -- 获取批量参数数组 比如请求 /?member[email]=1@qq.com&member[username]=haha local p= http_params('member[]') -- p= {email='1@qq.com',username='haha'} ``` **4.)http_redirect** ```lua -- 重定向到百度首页 http_redirect('https://www.baidu.com') ``` **5.)http_request** ```lua -- 重定向到百度首页 http_request(’url') http_request(’path') ``` # static 为静态文件夹映射,有扩展名的则映射单个文件 static_map: static: ./public/static img: ./tpl/img css: ./tpl/css js: ./tpl/js scs: ./tpl/scss fonts: ./tpl/fonts favo.ico: ./static/favo.ico # 首页文件 index: index.lua index.html ## html模板目录 tpl: ./tpl/*.html ## 是否启用index_all,启用后所有的请求都将重定向到index.lua,index配置无效 ## 比如:/foo/bar/?op=list , 将重定向到 /index.lua?_url=/foo/bar/?op=list index_all: 1 ## 服务类型,默认为空 都开启,也可以单独开启 ## type: http ## type: ws ## type: socket # socket启动 需要配置socket_type ,默认tcp服务 ## socket_type: tcp ## socket_type: udp ## 处理websocket的文件 ## ws_handler: 默认ws.lua ## 是否缓存lua代码 cache_code: 0 ``` ```lua -- 渲染html模板,index.html http_tpl('index',{title="hello world!"}) ```