add: 生成随机数接口
This commit is contained in:
1 parent
9c95404e93
commit
6515a6d84e
3 files changed
+148
-4
No files matched your search
+18
-4
@@ -1,11 +1,12 @@
|
||||
import { Hono } from "hono";
|
||||
import { ApiResponse } from "./modules/api_response";
|
||||
import { validator } from "hono/validator";
|
||||
import { postJson } from "./service/postJson";
|
||||
import { postUser } from "./service/postUser";
|
||||
import { isEmpty } from "./utils/is_empty";
|
||||
import { get } from "./service/get";
|
||||
import { getUser } from "./service/getUser";
|
||||
import { cors } from "hono/cors";
|
||||
import { bodyLimit } from "hono/body-limit";
|
||||
import { getRandom } from "./service/getRandom";
|
||||
|
||||
const tmpApp: Hono = new Hono()
|
||||
export const app = tmpApp.basePath("/test/")
|
||||
@@ -13,7 +14,7 @@ app.use("/test/*", cors())
|
||||
|
||||
// routers
|
||||
app.get("/user", (c) => {
|
||||
const re = get()
|
||||
const re = getUser()
|
||||
return c.json(ApiResponse.success(200, "Get user successfully", re))
|
||||
})
|
||||
|
||||
@@ -27,7 +28,7 @@ app.post(
|
||||
return val
|
||||
}),
|
||||
c => {
|
||||
const re = postJson()
|
||||
const re = postUser()
|
||||
return c.json(ApiResponse.success(200, "Add successfully", re))
|
||||
}
|
||||
)
|
||||
@@ -95,6 +96,19 @@ app.post("/file",
|
||||
}
|
||||
)
|
||||
|
||||
app.get("/random",
|
||||
validator("query", (val, c) => {
|
||||
if (isEmpty(val.typeList, val.length)) {
|
||||
c.status(400)
|
||||
return c.json(ApiResponse.err(400, "Param is invalid"))
|
||||
}
|
||||
return val
|
||||
}),
|
||||
c => {
|
||||
return getRandom(c)
|
||||
}
|
||||
)
|
||||
|
||||
app.notFound((c) => {
|
||||
console.log(`Not found [${c.req.method}]: ${c.req.path}`);
|
||||
return c.json(ApiResponse.err(404, "Not Found"))
|
||||
|
||||
Reference in new issue
Block a user