https://github.com/yrobot/faas.js
一个 文件即服务的 docker 镜像,支持 js/ts
https://github.com/yrobot/faas.js
bun docker faas javascript typescript
Last synced: 2 months ago
JSON representation
一个 文件即服务的 docker 镜像,支持 js/ts
- Host: GitHub
- URL: https://github.com/yrobot/faas.js
- Owner: Yrobot
- License: gpl-3.0
- Created: 2025-09-01T15:49:06.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2025-12-01T15:21:04.000Z (7 months ago)
- Last Synced: 2025-12-04T03:42:08.229Z (7 months ago)
- Topics: bun, docker, faas, javascript, typescript
- Language: TypeScript
- Homepage: https://hub.docker.com/r/yrobot/faas-js
- Size: 45.9 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FaaS.(js/ts)
> 一个 文件即服务的 docker 镜像
以 bun.sh 为基础环境,支持 js/ts 文件,以文件路径为请求路径,将 函数 以 服务的形式 进行暴露。
`api/hi/index.(ts/js)` => `POST/GET/... /api/hi`
- `api/hi/index.(ts/js)`
```ts
export function GET(req: Request) {
return new Response("hello world");
}
```
## Quick Start
```bash
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
```
### 在 `app/api` 下添加 ts 文件
> 文件 export 的 函数 需符合 Bun.serve 接口定义规范
> https://bun.com/docs/api/http#bun-serve
- 支持 `@` 的 ts alias
`util/time.ts`
```ts
import dayjs from "dayjs";
export const getTime = () => dayjs().format("YYYY-MM-DD HH:mm:ss");
```
`api/name/index.(ts/js)`
```ts
import { getTime } from "@/util/time";
export function POST(req: Request) {
return Response.json({
name: "FaaS.js",
time: getTime(),
});
}
```
## TODO
### 支持 Dynamic Routes
- `/api/xxx/:id`
- `/api/:scope/:id`
### 支持 Wildcard Routes
- `/api/all/*`
### 匹配优先级
> https://bun.com/docs/api/http#route-precedence
Routes are matched in order of specificity:
1. Exact routes (/users/all)
2. Parameter routes (/users/:id)
3. Wildcard routes (/users/\_)
4. Global catch-all (/\_)