const auth = G.headers().bind(headers => {
// TODO 认证
return G.pure(void 0)
})
const get = G.get().semiBind(G.pureText("get"))
const post = G.post().semiBind(G.pureText("post"))
const del = G.delete().semiBind(G.pureText("delete"))
// 所有不需要鉴权的路由
const pubRoute = G.path("/pub").semiBind(G.alts(
G.exactPath("/one/:a").bind(params => G.pureJson(params)),
G.exactPath("/two/:a").bind(params => G.pureJson(params)),
))
// 需要鉴权的路由
const authRoute = auth.semiBind(
get.alt(post).alt(del)
)
export const api = G.path("/api").semiBind(
pubRoute.alt(authRoute)
)
自己设计的,自己用,自己难受。
const server = serve({
routes: {
// Serve index.html for all unmatched routes.
"/*": index,
"/api/*": req=> {
return api.runWith404(req)
}
},
development: process.env.NODE_ENV !== "production" && {
// Enable browser hot reloading in development
hmr: true,
// Echo console logs from the browser to the server
console: true,
},
});
Link
click to show
click to show
https://github.com/diqye/piko
vibe coding 了一个 胶囊 App, 19M 。 秒打开。
我只搭好了环境(vibe 或者 通过npx init搭建的环境太拉跨), 定好了文件规则,其它都是pi coding 做的。