Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
fix: aggregation custom domain configure
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar committed Dec 12, 2019
1 parent 6c21939 commit 5c92e5b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/serverless-fc-starter/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('/test/index.test.ts', () => {
});
});

describe('wrapper web event', () => {
describe('wrapper web event fc', () => {
it('should ok with plain text', async () => {
const runtime = await start({});
const handle = asyncWrapper(async (...args) => {
Expand Down
7 changes: 6 additions & 1 deletion packages/serverless-midway-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@
1. 需要先进入 `../faas``../runtime-engine``../serverless-scf-starter``../serverless-fc-starter` 目录分别执行 `npm install --production`
2. 安装serverless框架 `npm i serverless -g`
3. 如果部署到阿里云:进入到 `/test/deployAliyun` 目录,执行 `serverless deploy`
3. 如果部署到腾讯云:进入到 `/test/deployTencent` 目录,执行 `serverless deploy`
3. 如果部署到腾讯云:进入到 `/test/deployTencent` 目录,执行 `serverless deploy`

### 高密度部署相关Q&A
1. 高密度部署只有在配置了http触发器的域名后可用
2. handler名称必须与文件名保持一致,这是为什么?
3. 高密度部署相关方法必须配置 path路径,切以 / 开头
35 changes: 20 additions & 15 deletions packages/serverless-midway-plugin/src/core/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ export class MidwayServerless {
this.serverless.service.provider = serviceyml.provider = { name: '', runtime: '' };
}

if (!this.serverless.service.provider.name) {
const prompt = new Select({
name: 'provider',
message: 'Which platform do you want to use?',
choices: ['阿里云函数计算 aliyun fc', '腾讯云函数 tencent scf']
});
const answers = await prompt.run();
const platform = answers.split(' ')[1];
if (!this.serverless.service.provider.name || this.options.platform) {
let platform = this.options.platform;
if (this.options.platform === true) {
const prompt = new Select({
name: 'provider',
message: 'Which platform do you want to use?',
choices: ['阿里云函数计算 aliyun fc', '腾讯云函数 tencent scf']
});
const answers = await prompt.run();
platform = answers.split(' ')[1];
}
serviceyml.provider.name = platform;
this.serverless.service.provider.name = platform;
this.serverless.pluginManager.serverlessConfigFile.provider.name = platform;
Expand Down Expand Up @@ -57,9 +60,16 @@ export class MidwayServerless {
return;
}

if (!this.serverless.service.custom || !this.serverless.service.custom.customDomain || !this.serverless.service.custom.customDomain.domainName) {
console.warn('If using aggregation deploy, please configure custom domain');
return;
}

this.serverless.cli.log('Aggregation Deploy');
for (const aggregationName in this.serverless.service.aggregation) {
const aggregationFuncName = `${aggregationName}`;
const aggregationFuncName = `aggregation${aggregationName}`;
this.serverless.service.functions[aggregationFuncName] = this.serverless.service.aggregation[aggregationName];
this.serverless.service.functions[aggregationFuncName].handler = `${aggregationFuncName}.handler`;
this.serverless.service.functions[aggregationFuncName]._isAggregation = true;
if (!this.serverless.service.functions[aggregationFuncName].events) {
this.serverless.service.functions[aggregationFuncName].events = [];
Expand All @@ -68,7 +78,6 @@ export class MidwayServerless {
const deployOrigin = this.serverless.service.aggregation[aggregationName].deployOrigin;

const allPaths = [];
// const httpEventCache = [];
let handlers = [];
if (this.serverless.service.aggregation[aggregationName].functions) {
handlers = this.serverless.service.aggregation[aggregationName].functions.map((functionName: string) => {
Expand All @@ -85,11 +94,6 @@ export class MidwayServerless {
if (!httpEvent || !httpEvent.http.path) {
return;
}
// // 进行缓存,以便于计算出来高密度通用path时,替换原有函数的path
// httpEventCache.push({
// name: functionName,
// index: httpEventIndex
// });
allPaths.push(httpEvent.http.path);
if (!deployOrigin) {
// 不把原有的函数进行部署
Expand All @@ -103,6 +107,7 @@ export class MidwayServerless {
}

const currentPath = this.commonPrefix(allPaths);
this.serverless.cli.log(` - using '${currentPath}/*' to deploy '${allPaths.join(`', '`)}'`);
this.serverless.service.functions[aggregationFuncName]._handlers = handlers;
this.serverless.service.functions[aggregationFuncName].events = [{ http: { method: 'get', path: currentPath + '/*' }}];
}
Expand Down
2 changes: 0 additions & 2 deletions packages/serverless-midway-plugin/src/core/providerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class ProviderBase {
if (handlerConf._ignore) {
continue;
}
console.log('handlerConf', handlerConf);
const [handlerFileName, name] = handlerConf.handler.split('.');
if (!files[handlerFileName]) {
files[handlerFileName] = {
Expand All @@ -87,7 +86,6 @@ export class ProviderBase {
});
}
}
console.log('files[handlerFileName]', files);

for (const file in files) {
const fileName = join(this.midwayBuildPath, `${file}.js`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Deploy extends CommandBase {

getHooks(): IHooks {
return {
'before:deploy:midway-deploy': () => {
'after:deploy:midway-deploy': () => {
}
};
}
Expand Down
46 changes: 20 additions & 26 deletions packages/serverless-midway-plugin/test/aggregation/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
service: serverless-midway-test

provider:
name: aliyun

aggregation:
common:
deployOrigin: false
functions:
- index
- hello
custom:
customDomain:
domainName: fctest.iam.gy
functions:
index:
handler: index.handler
events:
- http:
path: '/apis/index'
path: /apis/index
method: get
hello:
handler: hello.handler
events:
- http:
path: '/apis/hello'
path: /apis/hello
method: get

plugins:
- test

aggregation:
common:
deployOrigin: false
handler: common.handler
functions:
- index
- hello

custom:
customDomain:
domainName: fctest.iam.gy

package:
include:
exclude:
include: null
exclude: null
excludeDevDependencies: false
artifact: my-artifact.zip
artifact: my-artifact.zip
plugins:
- test
provider:
name: aliyun
service:
name: serverless-midway-test
2 changes: 1 addition & 1 deletion packages/serverless-scf-starter/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('/test/index.test.ts', () => {
});
});

describe('wrapper web event', () => {
describe('wrapper web event scf', () => {
it('should ok with plain text', async () => {
const runtime = await start();
const handle = asyncWrapper(async (...args) => {
Expand Down
15 changes: 10 additions & 5 deletions packages/spec-builder/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class SpecBuilder implements Builder {
return this.originData['provider'] || {};
}

getCustom() {
return this.originData['custom'];
}

getFunctions() {
return this.originData['functions'];
}
Expand Down Expand Up @@ -54,14 +58,15 @@ export class SpecBuilder implements Builder {

toJSON(): object {
return {
service: this.getService(),
provider: this.getProvider(),
aggregation: this.getAggregation(),
custom: this.getCustom(),
functions: this.getFunctions(),
layers: this.getLayers(),
resources: this.getResources(),
plugins: this.getPlugins(),
package: this.getPackage(),
aggregation: this.getAggregation()
plugins: this.getPlugins(),
provider: this.getProvider(),
resources: this.getResources(),
service: this.getService()
};
}
}

0 comments on commit 5c92e5b

Please sign in to comment.