An open API service indexing awesome lists of open source software.

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

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 (/\_)