cloudflare / cloudflare/moltworker

Add LINE webhook support (bypass Cloudflare Access + add public route)

Open
#101 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
10k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

## Summary
When using the LINE Messaging API channel plugin with Moltworker, LINE webhooks fail with a 302 redirect because:
1. Cloudflare Access blocks the incoming webhook request
2. No public route exists in the Worker to proxy the webhook to the sandbox

## Steps to Reproduce
1. Deploy Moltworker with Cloudflare Access enabled
2. Configure LINE channel in Clawdbot (`channels.line`)
3. Set LINE webhook URL to `https://.workers.dev/line/webhook`
4. Click "Verify" in LINE Developers Console
5. Get `302 Found` error

## Solution

### 1. Add public route in `src/routes/public.ts`

Add before `export { publicRoutes };`:

```typescript
// POST /line/webhook - LINE webhook endpoint (no auth required)
publicRoutes.post('/line/webhook', async (c) => {
const sandbox = c.get('sandbox');

try {
const response = await sandbox.containerFetch(
new Request(`http://localhost:${MOLTBOT_PORT}/line/webhook`, {
method: 'POST',
headers: c.req.raw.headers,
body: c.req.raw.body,
}),
MOLTBOT_PORT
);

return new Response(response.body, {
status: response.status,
headers: response.headers,
});
} catch (err) {
console.error('[LINE] Webhook proxy error:', err);
return c.json({ error: 'Gateway not ready' }, 503);
}
});
```

2. Create Cloudflare Access Bypass Application

1. Go to Cloudflare Zero Trust Dashboard
2. Access → Applications → Add application → Self-hosted
3. Set: • Application domain: .workers.dev
• Path: /line/webhook

4. Add policy: • Action: Bypass
• Include: Everyone

## Suggestion

Consider adding LINE webhook route to the default public.ts and documenting the Cloudflare Access bypass requirement in the README.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.