Skip to content

Commit 5807e13

Browse files
committed
chore: 改用 secrets 取代 secrets_store_secrets
1 parent b4d8b2d commit 5807e13

9 files changed

Lines changed: 37 additions & 44 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LINE_CHANNEL_SECRET=
2+
LINE_CHANNEL_ACCESS_TOKEN=

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ An “out-of-the-box” LINE Official Account webhook template for Cloudflare Wo
2323
2. Customize the code
2424
1. Message routing/handling: `src/eventRouter.ts`
2525
2. Config: `wrangler.toml`
26-
1. `name`
27-
2. `secrets_store_secrets`
28-
1. `store_id` (both entries) -> replace with your account `store_id`
26+
1. `name` 2. `secrets`
27+
1. `LINE_CHANNEL_SECRET`
28+
2. `LINE_CHANNEL_ACCESS_TOKEN`
29+
-> set these using `wrangler secret put` or the Cloudflare dashboard
2930
3. Deploy
3031
1. Cloudflare
3132
2. `Workers & Pages`
@@ -35,10 +36,10 @@ An “out-of-the-box” LINE Official Account webhook template for Cloudflare Wo
3536

3637
## ⚙️ Configuration
3738

38-
| Type | Name | Description | Purpose |
39-
| :-----------: | :-----------------------: | :----------------------------------------: | :------: |
40-
| Secrets Store | LINE_CHANNEL_SECRET | LINE Official Account channel secret | Validate |
41-
| Secrets Store | LINE_CHANNEL_ACCESS_TOKEN | LINE Official Account channel access token | Validate |
39+
| Type | Name | Description | Purpose |
40+
| :-----: | :-----------------------: | :----------------------------------------: | :------: |
41+
| Secrets | LINE_CHANNEL_SECRET | LINE Official Account channel secret | Validate |
42+
| Secrets | LINE_CHANNEL_ACCESS_TOKEN | LINE Official Account channel access token | Validate |
4243

4344
<!-- Links -->
4445
<!-- Cloudflare -->

README.zh-TW.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ Language: [English](README.md) | [繁體中文](README.zh-TW.md)
2525
2. 修改程式
2626
1. 訊息處理路由`src/eventRouter.ts`
2727
2. 配置檔案`wrangler.toml`
28-
1. `name`
29-
2. `secrets_store_secrets`
30-
1. `store_id`(兩個都要) -> 修改為帳號的`store_id`
28+
1. `name` 2. `secrets`
29+
1. `LINE_CHANNEL_SECRET`
30+
2. `LINE_CHANNEL_ACCESS_TOKEN`
31+
-> 可使用 `wrangler secret put` 或在 Cloudflare 控制台中設定
3132
3. 部署
3233
1. Cloudflare
3334
2. `Workers 和 Pages`
@@ -37,10 +38,10 @@ Language: [English](README.md) | [繁體中文](README.zh-TW.md)
3738

3839
## ⚙️配置
3940

40-
| 類型 | 名稱 | 配置 | 用途 |
41-
| :-----------: | :-----------------------: | :----------------------------------: | :--: |
42-
| Secrets Store | LINE_CHANNEL_SECRET | Line 官方帳號的 channel secret | 驗證 |
43-
| Secrets Store | LINE_CHANNEL_ACCESS_TOKEN | Line 官方帳號的 channel access token | 驗證 |
41+
| 類型 | 名稱 | 配置 | 用途 |
42+
| :-----: | :-----------------------: | :----------------------------------: | :--: |
43+
| Secrets | LINE_CHANNEL_SECRET | Line 官方帳號的 channel secret | 驗證 |
44+
| Secrets | LINE_CHANNEL_ACCESS_TOKEN | Line 官方帳號的 channel access token | 驗證 |
4445

4546
<!-- 網址們 -->
4647
<!-- Cloduflare -->

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"format": "prettier . --write",
1313
"format:check": "prettier . --check",
1414
"typecheck": "tsc --noEmit",
15-
"start": "wrangler dev",
16-
"dev": "wrangler dev",
17-
"deploy": "wrangler deploy",
15+
"start": "wrangler dev --env--file .env",
16+
"dev": "wrangler dev --env--file .env",
17+
"deploy": "wrangler deploy --secrets-file .env",
1818
"prestart": "npm run types:sync",
1919
"predev": "npm run types:sync",
2020
"predeploy": "npm run types:sync"

src/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function router(request: Request, env: Env, ctx: ExecutionContext)
88
return new Response("Method Not Allowed", { status: 405 });
99
}
1010
// 取得環境變數
11-
const [channelSecret, channelAccessToken] = await Promise.all([env.LINE_CHANNEL_SECRET.get(), env.LINE_CHANNEL_ACCESS_TOKEN.get()]);
11+
const [channelSecret, channelAccessToken] = await Promise.all([env.LINE_CHANNEL_SECRET, env.LINE_CHANNEL_ACCESS_TOKEN]);
1212
if (!channelSecret || !channelAccessToken) {
1313
return new Response("Server misconfigured", { status: 500 });
1414
}

test/router.extra.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ vi.mock("../src/eventRouter", () => ({
1111

1212
import { router } from "../src/router";
1313

14-
const mockEnv = {
15-
LINE_CHANNEL_SECRET: { get: vi.fn() },
16-
LINE_CHANNEL_ACCESS_TOKEN: { get: vi.fn() },
14+
const mockEnv: any = {
15+
LINE_CHANNEL_SECRET: "secret",
16+
LINE_CHANNEL_ACCESS_TOKEN: "accessToken",
1717
};
1818

1919
describe("router extra branches", () => {
2020
beforeEach(() => {
2121
vi.clearAllMocks();
22-
mockEnv.LINE_CHANNEL_SECRET.get.mockResolvedValue("secret");
23-
mockEnv.LINE_CHANNEL_ACCESS_TOKEN.get.mockResolvedValue("accessToken");
22+
mockEnv.LINE_CHANNEL_SECRET = "secret";
23+
mockEnv.LINE_CHANNEL_ACCESS_TOKEN = "accessToken";
2424
});
2525

2626
it("returns 400 when body is not valid JSON", async () => {

test/router.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
22
import { router } from "../src/router";
33
import { hmacSHA256Base64 } from "../src/utils/hmacSHA256Base64";
44

5-
const mockEnv = {
6-
LINE_CHANNEL_SECRET: { get: vi.fn() },
7-
LINE_CHANNEL_ACCESS_TOKEN: { get: vi.fn() },
5+
const mockEnv: any = {
6+
LINE_CHANNEL_SECRET: "secret",
7+
LINE_CHANNEL_ACCESS_TOKEN: "accessToken",
88
};
99

1010
describe("router", () => {
1111
beforeEach(() => {
1212
vi.clearAllMocks();
13-
mockEnv.LINE_CHANNEL_SECRET.get.mockResolvedValue("secret");
14-
mockEnv.LINE_CHANNEL_ACCESS_TOKEN.get.mockResolvedValue("accessToken");
13+
mockEnv.LINE_CHANNEL_SECRET = "secret";
14+
mockEnv.LINE_CHANNEL_ACCESS_TOKEN = "accessToken";
1515
});
1616

1717
it("returns 405 for non-POST methods", async () => {
@@ -43,7 +43,7 @@ describe("router", () => {
4343
});
4444

4545
it("returns 500 if server is misconfigured", async () => {
46-
mockEnv.LINE_CHANNEL_SECRET.get.mockResolvedValue(null);
46+
mockEnv.LINE_CHANNEL_SECRET = null;
4747
const request = new Request("https://example.com", { method: "POST" });
4848
const response = await router(request, mockEnv as any, {} as any);
4949

worker-configuration.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable */
2-
// Generated by Wrangler by running `wrangler types` (hash: a1d078614f11bca5b7cd9a5c71cfb1b4)
2+
// Generated by Wrangler by running `wrangler types` (hash: 9fa3ad024bc190dbb1e4e22e0e58b6ea)
33
// Runtime types generated with workerd@1.20260520.1 2026-01-28
44
interface __BaseEnv_Env {
5-
LINE_CHANNEL_SECRET: SecretsStoreSecret;
6-
LINE_CHANNEL_ACCESS_TOKEN: SecretsStoreSecret;
75
CF_VERSION_METADATA: WorkerVersionMetadata;
6+
LINE_CHANNEL_SECRET: string;
7+
LINE_CHANNEL_ACCESS_TOKEN: string;
88
}
99
declare namespace Cloudflare {
1010
interface GlobalProps {

wrangler.jsonc

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,7 @@
33
"name": "line-workers-template",
44
"main": "src/_index.ts",
55
"compatibility_date": "2026-01-28",
6-
"secrets_store_secrets": [
7-
{
8-
"binding": "LINE_CHANNEL_SECRET",
9-
"store_id": "9c70a29302f948cb9ff3ddbd8d2afb49",
10-
"secret_name": "LINE_CHANNEL_SECRET",
11-
},
12-
{
13-
"binding": "LINE_CHANNEL_ACCESS_TOKEN",
14-
"store_id": "9c70a29302f948cb9ff3ddbd8d2afb49",
15-
"secret_name": "LINE_CHANNEL_ACCESS_TOKEN",
16-
},
17-
],
6+
"secrets": { "required": ["LINE_CHANNEL_SECRET", "LINE_CHANNEL_ACCESS_TOKEN"] },
187
"placement": {
198
"mode": "smart",
209
},

0 commit comments

Comments
 (0)