支持 js websocket

This commit is contained in:
dragon
2025-11-19 15:56:32 +08:00
parent 268f21c2af
commit 043b00bbb7
25 changed files with 617 additions and 69 deletions

View File

@@ -0,0 +1,10 @@
routes:
- path: "get"
js:
exec: "index.js"
debug: true
- path: "put"
js:
exec: "index.js"
debug: true

14
examples/js_kv/index.html Normal file
View File

@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JS 概念验证</title>
</head>
<body>
<a href="/get">查询数据</a>
<a href="/put">更新数据</a>
</body>
</html>

19
examples/js_kv/index.js Normal file
View File

@@ -0,0 +1,19 @@
var db = kv.repo("self");
if(request.path == "put"){
data = db.get('key')
if(data == undefined){
db.set('key','0')
}else {
db.set('key',(parseInt(data)+1).toString())
}
}
response.write("当前存储的数值为 " + db.get('key'))
var test = kv.repo("test");
for (let i = 0; i < 500; i++) {
test.set("key" + i,"value" + i);
}
var list = test.list()
console.log(list.keys.length)
console.log(list.cursor)
console.log(list.hasNext)