一个 文件即服务的 docker 镜像
以 bun.sh 为基础环境,支持 js/ts 文件,以文件路径为请求路径,将 函数 以 服务的形式 进行暴露。
api/hi/index.(ts/js) => POST/GET/... /api/hi
api/hi/index.(ts/js)
export function GET(req: Request) {
return new Response("hello world");
}docker run -d -p 3000:3000 --name faas-js \
-v $DOCKER_DATA_DIR/faas-js/app:/app \
-e POST=3000 \
--user $(id -u):$(id -g) \ # 推荐使用当前用户作为运行用户,这影响到文件权限 # 便于直接在此文件系统下debug和增加逻辑
ghcr.io/yrobot/faas-js:latest文件 export 的 函数 需符合 Bun.serve 接口定义规范 https://bun.com/docs/api/http#bun-serve
- 支持
@的 ts alias
util/time.ts
import dayjs from "dayjs";
export const getTime = () => dayjs().format("YYYY-MM-DD HH:mm:ss");api/name/index.(ts/js)
import { getTime } from "@/util/time";
export function POST(req: Request) {
return Response.json({
name: "FaaS.js",
time: getTime(),
});
}/api/xxx/:id/api/:scope/:id
/api/all/*
Routes are matched in order of specificity:
- Exact routes (/users/all)
- Parameter routes (/users/:id)
- Wildcard routes (/users/_)
- Global catch-all (/_)