API 채널 엔드포인트
이 플러그인의 설치 단계와 전체 마크다운 가이드가 포함된 설정 프롬프트를 복사하세요.
Capgo에서 채널은 앱 업데이트를 관리하는 핵심 메커니즘입니다. 셀프 호스팅 모드에서는 디바이스 할당, 채널 조회, 채널 관리 작업을 처리하는 채널 엔드포인트를 구현해야 합니다.
채널 이해하기
“채널 이해하기” 섹션채널을 통해 다음을 수행할 수 있습니다:
- 업데이트 배포 제어: 사용자 그룹별로 서로 다른 앱 버전 할당
- A/B 테스트: 특정 사용자 세그먼트를 대상으로 신규 기능 테스트
- 단계적 배포: 리스크 최소화를 위한 단계적 업데이트 배포
- 환경 분리: 개발, 스테이징, 프로덕션 업데이트 분리
다음에서 채널 엔드포인트 URL을 설정하세요: capacitor.config.json:
{ "plugins": { "CapacitorUpdater": { "channelUrl": "https://myserver.com/api/channel_self" } }}플러그인은 엔드포인트에서 처리해야 할 다음과 같은 채널 작업을 수행합니다:
1. 호환되는 채널 목록 조회 (GET 요청)
“1. List Compatible Channels (GET Request)” 섹션플러그인이 호출될 때 listChannels()기기와 호환되는 모든 채널을 가져오기 위해 GET 요청을 보냅니다. 이 요청은 기기의 환경(dev/prod, emulator/real device)과 일치하며, 공개 액세스 또는 셀프 할당이 가능한 채널을 반환합니다.
요청 형식
“Request Format” 섹션// GET /api/channel_self// Headers:{ "Content-Type": "application/json"}
// Query parameters:interface ListChannelsRequest { app_id: string platform: "ios" | "android" | "electron" is_emulator: boolean is_prod: boolean key_id?: string}응답 형식
“Response Format” 섹션[ { "id": 1, "name": "production", "public": true, "allow_self_set": false }, { "id": 2, "name": "beta", "public": false, "allow_self_set": true }]채널 유형 이해하기
“채널 유형 이해하기” 섹션응답에는 각 채널마다 두 가지 중요한 플래그가 포함됩니다:
-
public: true: 이 채널은 기본 채널. 기기에서 다음 명령어를 사용하여 직접 채널을 할당할 수 없습니다:setChannel(). 대신, 기기에서 채널 할당을 해제하는 경우 (unsetChannel()), 디바이스의 조건과 일치하면 이 public channel에서 자동으로 업데이트를 받게 됩니다. -
allow_self_set: true: 이 채널은 직접 지정 가능한 채널. 기기에서 다음을 사용하여 이 채널을 직접 지정할 수 있습니다:setChannel(). 이는 베타 테스트, A/B 테스트 또는 사용자가 특정 업데이트 트랙을 직접 선택하도록 할 때 유용합니다.
2. 채널 조회 (PUT 요청)
“2. Get Channel (PUT Request)” 섹션플러그인이 호출할 때 getChannel(), 기기의 현재 채널 할당 정보를 가져오기 위해 PUT 요청을 보냅니다.
요청 형식
“요청 형식” 섹션// PUT /api/channel_self// Headers:{ "Content-Type": "application/json"}
// Body:interface GetChannelRequest { device_id: string app_id: string platform: "ios" | "android" | "electron" plugin_version: string version_build: string version_code: string version_name: string is_emulator: boolean is_prod: boolean defaultChannel?: string channel?: string // For newer plugin versions, contains local channel override}응답 형식
“Response Format” 섹션{ "status": "ok", "channel": "production", "allowSet": true, "message": "", "error": ""}3. 채널 설정 (POST 요청)
“3. 채널 설정 (POST 요청)” 섹션플러그인이 호출될 때 setChannel(), 기기를 특정 채널에 할당하기 위해 POST 요청을 보냅니다.
요청 형식
“Request Format” 섹션// POST /api/channel_selfinterface SetChannelRequest { device_id: string app_id: string channel: string platform: "ios" | "android" | "electron" plugin_version: string version_build: string version_code: string version_name: string is_emulator: boolean is_prod: boolean}응답 형식
“Response Format” 섹션{ "status": "ok", "message": "Device assigned to channel successfully", "error": ""}오류 사례
“Error Cases” 섹션디바이스가 특정 public channel에 (다음과 같은 public: true)을 할당하려고 하면, 엔드포인트에서 에러를 반환해야 합니다:
{ "status": "error", "error": "public_channel_self_set_not_allowed", "message": "This channel is public and does not allow device self-assignment. Unset the channel and the device will automatically use the public channel."}디바이스가 직접 할당(self-assignment)을 허용하지 않는 채널에 할당을 시도할 때:
{ "status": "error", "error": "channel_self_set_not_allowed", "message": "This channel does not allow devices to self associate"}4. 채널 설정 해제 (DELETE 요청)
“4. Unset Channel (DELETE Request)” 섹션플러그인이 호출될 때 unsetChannel(), 디바이스의 채널 할당을 해제하기 위해 DELETE 요청을 보냅니다.
요청 형식
“Request Format” 섹션// DELETE /api/channel_selfinterface UnsetChannelRequest { device_id: string app_id: string platform: "ios" | "android" | "electron" plugin_version: string version_build: string version_code: string version_name: string}채널 엔드포인트를 구현하는 JavaScript 예시입니다:
interface ChannelRequest { device_id: string app_id: string channel?: string platform: "ios" | "android" | "electron" plugin_version: string version_build: string version_code: string version_name: string}
interface ChannelResponse { status: "ok" | "error" channel?: string allowSet?: boolean message?: string error?: string}
export const handler = async (event) => { const method = event.httpMethod || event.method const body = JSON.parse(event.body || '{}') as ChannelRequest
const { device_id, app_id, channel, platform } = body
try { switch (method) { case 'GET': return await getDeviceChannel(device_id, app_id)
case 'POST': return await setDeviceChannel(device_id, app_id, channel!, platform)
case 'DELETE': return await unsetDeviceChannel(device_id, app_id)
default: return { status: "error", error: "Method not allowed" } } } catch (error) { return { status: "error", error: error.message } }}
async function getDeviceChannel(deviceId: string, appId: string): Promise<ChannelResponse> { // Query your database for device channel assignment const assignment = await database.getDeviceChannel(deviceId, appId)
if (assignment) { return { status: "ok", channel: assignment.channel, allowSet: assignment.allowSelfAssign } }
// Return default channel if no assignment found return { status: "ok", channel: "production", // Your default channel allowSet: true }}
async function setDeviceChannel( deviceId: string, appId: string, channel: string, platform: string): Promise<ChannelResponse> { // Validate channel exists and allows self-assignment const channelConfig = await database.getChannelConfig(channel, appId)
if (!channelConfig) { return { status: "error", error: "Channel not found" } }
if (!channelConfig.allowDeviceSelfSet) { return { status: "error", error: "Channel does not allow self-assignment" } }
// Check platform restrictions if (platform === "ios" && !channelConfig.ios) { return { status: "error", error: "Channel not available for iOS" } }
if (platform === "android" && !channelConfig.android) { return { status: "error", error: "Channel not available for Android" } }
if (platform === "electron" && !channelConfig.electron) { return { status: "error", error: "Channel not available for Electron" } }
// Save the assignment await database.setDeviceChannel(deviceId, appId, channel)
return { status: "ok", message: "Device assigned to channel successfully" }}
async function unsetDeviceChannel(deviceId: string, appId: string): Promise<ChannelResponse> { // Remove device channel assignment await database.removeDeviceChannel(deviceId, appId)
return { status: "ok", message: "Device channel assignment removed" }}채널 구성
“채널 설정” 섹션채널 시스템은 다음 설정 옵션들을 지원해야 합니다:
interface ChannelConfig { name: string appId: string
// Platform targeting ios: boolean // Allow updates to iOS devices android: boolean // Allow updates to Android devices electron: boolean // Allow updates to Electron apps
// Device type restrictions allow_emulator: boolean // Allow updates on emulator/simulator devices allow_device: boolean // Allow updates on real/physical devices
// Build type restrictions allow_dev: boolean // Allow updates on development builds (is_prod=false) allow_prod: boolean // Allow updates on production builds (is_prod=true)
// Channel assignment public: boolean // Default channel - devices fall back to this when no override allowDeviceSelfSet: boolean // Allow devices to self-assign via setChannel()
// Update policies disableAutoUpdate: "major" | "minor" | "version_number" | "none" disableAutoUpdateUnderNative: boolean}기기 필터링 로직
“디바이스 필터링 로직” 섹션호환 가능한 채널 목록을 반환할 때(GET 요청), 다음 조건에 따라 채널을 필터링해야 합니다:
- 플랫폼 확인: 채널이 해당 디바이스의 플랫폼을 허용해야 함
ios,android, 또는electron) - 디바이스 유형 확인:
- 만약
is_emulator=true: 채널에 다음 항목이 포함되어야 합니다:allow_emulator=true - 만약
is_emulator=false: 채널에 다음 항목이 포함되어야 합니다:allow_device=true
- 만약
- Build 유형 확인:
- 만약
is_prod=true: 채널에 다음 항목이 포함되어야 합니다:allow_prod=true - 만약
is_prod=false: 채널에 다음 항목이 포함되어야 합니다:allow_dev=true
- 만약
- Visibility 확인: 채널은 다음 중 하나여야 합니다:
public=true또는allow_device_self_set=true
// Example filtering logicfunction getCompatibleChannels( platform: 'ios' | 'android' | 'electron', isEmulator: boolean, isProd: boolean, channels: ChannelConfig[]): ChannelConfig[] { return channels.filter(channel => { // Platform check if (!channel[platform]) return false
// Device type check if (isEmulator && !channel.allow_emulator) return false if (!isEmulator && !channel.allow_device) return false
// Build type check if (isProd && !channel.allow_prod) return false if (!isProd && !channel.allow_dev) return false
// Must be accessible (public or self-assignable) if (!channel.public && !channel.allowDeviceSelfSet) return false
return true })}데이터베이스 스키마 예시
“데이터베이스 스키마 예시” 섹션채널 설정과 디바이스 할당 정보를 저장해야 합니다:
-- Channels tableCREATE TABLE channels ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, app_id VARCHAR(255) NOT NULL,
-- Platform targeting ios BOOLEAN DEFAULT true, android BOOLEAN DEFAULT true, electron BOOLEAN DEFAULT true,
-- Device type restrictions allow_emulator BOOLEAN DEFAULT true, -- Allow emulator/simulator devices allow_device BOOLEAN DEFAULT true, -- Allow real/physical devices
-- Build type restrictions allow_dev BOOLEAN DEFAULT true, -- Allow development builds allow_prod BOOLEAN DEFAULT true, -- Allow production builds
-- Channel assignment public BOOLEAN DEFAULT false, -- Default channel (fallback) allow_device_self_set BOOLEAN DEFAULT false, -- Allow self-assignment
-- Update policies disable_auto_update VARCHAR(50) DEFAULT 'none', disable_auto_update_under_native BOOLEAN DEFAULT false,
created_at TIMESTAMP DEFAULT NOW(), UNIQUE(name, app_id));
-- Device channel assignments tableCREATE TABLE device_channels ( id SERIAL PRIMARY KEY, device_id VARCHAR(255) NOT NULL, app_id VARCHAR(255) NOT NULL, channel_name VARCHAR(255) NOT NULL, assigned_at TIMESTAMP DEFAULT NOW(), UNIQUE(device_id, app_id));에러 핸들링
“Error Handling” 섹션일반적인 에러 시나리오를 처리하세요:
// Channel not found{ "status": "error", "error": "Channel 'beta' not found"}
// Self-assignment not allowed{ "status": "error", "error": "Channel does not allow device self-assignment"}
// Platform not supported{ "status": "error", "error": "Channel not available for this platform"}
// Invalid request{ "status": "error", "error": "Missing required field: device_id"}모범 사례
“권장 사항” 섹션- 보안: 비즈니스 규칙에 따라 모든 채널 할당을 검증하세요
- 로깅: 감사 및 디버깅을 위해 모든 채널 작업을 기록하세요
- 성능: 데이터베이스 쿼리를 줄이기 위해 채널 설정을 캐싱하세요
- 검증device_id 및 app_id의 유효성을 확인하세요
- Rate Limiting남용 방지를 위해 Rate Limiting을 구현하세요
Updates 연동
“Updates 연동” 섹션채널 할당은 다음 항목과 함께 작동합니다: API 업데이트 엔드포인트디바이스가 업데이트를 요청하면, 할당된 채널을 확인하여 어떤 버전을 제공할지 결정합니다:
async function getUpdateForDevice(deviceId: string, appId: string) { // Get device's channel assignment const channelAssignment = await getDeviceChannel(deviceId, appId) const channel = channelAssignment.channel || 'production'
// Get the version assigned to this channel const channelVersion = await getChannelVersion(channel, appId)
return { version: channelVersion.version, url: channelVersion.url, checksum: channelVersion.checksum }}이를 통해 업데이트 배포 방식을 완전히 제어할 수 있는 완벽한 셀프 호스팅 채널 관리 시스템을 구축할 수 있습니다.
Channel API 엔드포인트에서 계속하기
“Channel API 엔드포인트에서 계속하기” 섹션사용 중이라면 API 채널 엔드포인트 채널 라우팅과 단계적 배포를 계획하려면, 다음을 연결하세요: @capgo/capacitor-updater 사용하기 네이티브 기능의 경우 @capgo/capacitor-updater 사용하기에서, 채널 Channels의 구현 세부 사항은 다음을 참고하세요: 채널 Channels의 구현 세부 사항은 다음을 참고하세요: 채널 Channels의 구현 세부 사항은, Beta Testing 솔루션 Beta Testing Solution의 제품 워크플로우는.