兼容linux
This commit is contained in:
@@ -1,17 +1,10 @@
|
||||
require "website"
|
||||
|
||||
-- 通用入口函数
|
||||
route = {"/",GET}
|
||||
function access()
|
||||
|
||||
-- MYSQL执行SELECT查询map表
|
||||
--local result = mysql:select():table("map"):query()
|
||||
|
||||
-- 构建回复数据
|
||||
--local data = result:table()
|
||||
|
||||
local data = {
|
||||
name = "Fast Web 快速网站开发框架"
|
||||
}
|
||||
-- 返回JSON数据
|
||||
json(data)
|
||||
reply(200,"OK",data)
|
||||
end
|
||||
@@ -1,19 +1,6 @@
|
||||
require "website"
|
||||
-- MYSQL数据库池
|
||||
|
||||
|
||||
function initMysql()
|
||||
local pool = mysql_pool.new()
|
||||
if pool:start("127.0.0.1","test","123456","test","utf8mb4",3306,10) == false then
|
||||
print("start mysql pool failed")
|
||||
return false
|
||||
end
|
||||
global_regist("mysql",pool:self())
|
||||
return true
|
||||
end
|
||||
print("init fast web success!")
|
||||
|
||||
|
||||
if initMysql() == false then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
@@ -1,9 +1,7 @@
|
||||
function access()
|
||||
|
||||
if request:pstring("key") == "123456" then
|
||||
return true
|
||||
require "website"
|
||||
function access()
|
||||
if param("key") == nil or param("key") ~= "123465" then
|
||||
print("is not found key")
|
||||
end
|
||||
|
||||
response:send("密钥不正确,已被拦截器拦截.")
|
||||
return false
|
||||
return true
|
||||
end
|
||||
@@ -1,8 +1,23 @@
|
||||
local dkjson = require 'dkjson'
|
||||
|
||||
function json(data)
|
||||
response:header("Content-Type","application/json")
|
||||
response:send(dkjson.encode(data))
|
||||
end
|
||||
function session()
|
||||
return request:session(request:token())
|
||||
end
|
||||
function param(name)
|
||||
return request:param(name,false)
|
||||
end
|
||||
function param_throw(name)
|
||||
return request:param(name,true)
|
||||
end
|
||||
function reply(code,msg,data)
|
||||
local data ={
|
||||
code =code,
|
||||
msg = msg,
|
||||
data = data
|
||||
}
|
||||
json(data)
|
||||
end
|
||||
Reference in New Issue
Block a user