# 快速開始

從原始碼建置 HakoRun、補齊語言執行環境，並上傳與呼叫第一個函式。

## 前置需求

| 項目 | 需求 |
|------|------|
| Go | 1.25 以上（`go.mod`） |
| 作業系統 | Linux：`bwrap`、`systemd-run` 與可用的 systemd user session；macOS：內建 `sandbox-exec` |
| Python | `python3` |
| Node.js | `node` 與 `npm` |
| TypeScript | 全域 `tsx`、`typescript`、`esbuild`，以及專案根目錄的本地 `esbuild` |
| Redis | 僅在以 `-tags redis` 建置時需要 |

## 安裝

```bash
git clone https://github.com/pardnchiu/HakoRun.git
cd HakoRun
npm install -g tsx typescript esbuild
npm install esbuild
make build          # 預設 ToriiDB，產出 bin/hako
make build redis    # 改用 Redis 儲存
```

HakoRun 以啟動時的工作目錄解析 `internal/resource/wrapper.{py,js,ts}`，執行檔必須在專案根目錄啟動；`go install` 取得的獨立執行檔找不到 wrapper。

Linux 啟動時若缺 `node`、`tsc`、`esbuild` 或 `python3`，會以 `sudo` 透過 `apt`／`dnf`／`pacman`／`apk` 安裝 `bubblewrap`、`nodejs`、`npm`、`python3`；`tsc` 與 `esbuild` 不在自動安裝範圍，需先手動安裝，否則每次啟動都會觸發安裝流程。

## 啟動

```bash
cp .env.example .env   # Makefile 會載入 .env
make run               # 或 ./bin/hako
```

伺服器預設監聽 `:8080`，收到 `SIGINT`／`SIGTERM` 後在 5 秒內優雅關閉。

## 第一個函式

上傳後以路徑呼叫：

```bash
curl --fail-with-body -X POST http://localhost:8080/upload \
  -H "Content-Type: application/json" \
  -d '{"path": "math/add", "language": "python", "code": "return event[\"a\"] + event[\"b\"]"}'

curl --fail-with-body -X POST http://localhost:8080/run/math/add \
  -H "Content-Type: application/json" \
  -d '{"input": "{\"a\": 3, \"b\": 5}"}'
```

第二個請求回傳：

```json
{ "data": 8, "type": "number" }
```

## 相關頁面

- [設定](/zh/configuration)
- [核心概念](/zh/core-concepts)
- [API 參考](/zh/api-reference)
