diff --git a/src/modules/apigw/entities/api.ts b/src/modules/apigw/entities/api.ts index 69e6975..7f9535c 100644 --- a/src/modules/apigw/entities/api.ts +++ b/src/modules/apigw/entities/api.ts @@ -440,7 +440,8 @@ export default class ApiEntity { const authType = endpoint?.auth ? 'SECRET' : endpoint?.authType ?? 'NONE'; const apiInputs: { [key: string]: any } = { - protocol: endpoint?.protocol ?? 'HTTP', + // protocol: endpoint?.protocol ?? 'HTTP', + protocol: endpoint?.protocolType ?? 'HTTP', serviceId: serviceId, apiName: endpoint?.apiName ?? 'index', apiDesc: endpoint?.description, @@ -450,7 +451,7 @@ export default class ApiEntity { serviceType: endpoint?.serviceType ?? 'SCF', requestConfig: { path: endpoint?.path, - method: endpoint?.method, + method: endpoint?.protocolType === 'WEBSOCKET' ? 'GET' : endpoint?.method, }, serviceTimeout: endpoint?.serviceTimeout ?? 15, responseType: endpoint?.responseType ?? 'HTML', diff --git a/src/modules/apigw/entities/service.ts b/src/modules/apigw/entities/service.ts index c86c21e..b9e67c2 100644 --- a/src/modules/apigw/entities/service.ts +++ b/src/modules/apigw/entities/service.ts @@ -263,8 +263,8 @@ export default class ServiceEntity { serviceId, protocols, netTypes, - serviceName = 'serverless', - serviceDesc = 'Created By Serverless', + serviceName = '', + serviceDesc, } = serviceConf; let detail: Detail | null; @@ -284,6 +284,7 @@ export default class ServiceEntity { if (detail) { detail.InnerSubDomain = detail.InternalSubDomain; exist = true; + serviceName ? (outputs.serviceName = detail.ServiceName) : ''; outputs.serviceId = detail!.ServiceId; outputs.subDomain = detail!.OuterSubDomain && detail!.InnerSubDomain @@ -312,11 +313,18 @@ export default class ServiceEntity { const apiInputs = { Action: 'ModifyService' as const, serviceId, - serviceDesc: serviceDesc || detail.ServiceDesc, - serviceName: serviceName || detail.ServiceName, + serviceDesc: serviceDesc || detail.ServiceDesc || undefined, + serviceName: serviceName || detail.ServiceName || undefined, protocol: protocols, netTypes: netTypes, }; + if (!serviceName) { + delete apiInputs.serviceName; + } + if (!serviceDesc) { + delete apiInputs.serviceDesc; + } + await this.request(apiInputs); } } diff --git a/src/modules/scf/interface.ts b/src/modules/scf/interface.ts index 15e1976..d07a360 100644 --- a/src/modules/scf/interface.ts +++ b/src/modules/scf/interface.ts @@ -14,6 +14,16 @@ export interface FunctionCode { Args?: string; }; } + +export interface WSParams { + idleTimeOut?: number; + IdleTimeOut?: number; +} +export interface ProtocolParams { + wsParams?: WSParams; + WSParams?: WSParams; +} + export interface BaseFunctionConfig { FunctionName: string; Code?: FunctionCode; @@ -53,6 +63,8 @@ export interface BaseFunctionConfig { AsyncRunEnable?: 'TRUE' | 'FALSE'; TraceEnable?: 'TRUE' | 'FALSE'; InstallDependency?: 'TRUE' | 'FALSE'; + ProtocolType?: string; + ProtocolParams?: ProtocolParams; } export interface TriggerType { @@ -215,6 +227,9 @@ export interface ScfCreateFunctionInputs { // 异步调用重试配置 msgTTL?: number; // 消息保留时间,单位秒 retryNum?: number; // 重试次数 + + protocolType?: string; + protocolParams?: ProtocolParams; } export interface ScfUpdateAliasTrafficInputs { @@ -257,6 +272,8 @@ export interface ScfDeployInputs extends ScfCreateFunctionInputs { // 是否忽略触发器操作流程 ignoreTriggers?: boolean; + protocolType?: string; + protocolParams?: ProtocolParams; } export interface ScfDeployOutputs { diff --git a/src/modules/scf/utils.ts b/src/modules/scf/utils.ts index fef8daf..73f07d2 100644 --- a/src/modules/scf/utils.ts +++ b/src/modules/scf/utils.ts @@ -1,4 +1,4 @@ -import { ScfCreateFunctionInputs, BaseFunctionConfig } from './interface'; +import { ScfCreateFunctionInputs, BaseFunctionConfig, ProtocolParams } from './interface'; const CONFIGS = require('./config').default; // get function basement configure @@ -66,6 +66,17 @@ export const formatInputs = (inputs: ScfCreateFunctionInputs) => { } // 非必须参数 + if (inputs.type === 'web') { + if (inputs.protocolType) { + functionInputs.ProtocolType = inputs.protocolType; + if (inputs.protocolParams?.wsParams?.idleTimeOut) { + const protocolParams: ProtocolParams = {}; + protocolParams.WSParams = { IdleTimeOut: inputs.protocolParams?.wsParams?.idleTimeOut }; + functionInputs.ProtocolParams = protocolParams; + } + } + } + if (inputs.role) { functionInputs.Role = inputs.role; }