Skip to content

Commit

Permalink
fix: serverless app layers support (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar authored Mar 9, 2021
1 parent 9a7c2ca commit 45cd7fe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
27 changes: 26 additions & 1 deletion packages-serverless/serverless-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,13 @@ export class Framework
}

const triggerMap = this.getTriggerMap();

const layers = this.getLayers();
const { Framework } = require(usageFaasModulePath);
const startResult = await start2({
appDir,
baseDir: currentBaseDir,
framework: Framework,
layers: layers,
starter: require(starterName),
initializeContext: undefined,
});
Expand Down Expand Up @@ -314,4 +315,28 @@ export class Framework
process.send({ type: 'dev:' + type, data, id: msg.id });
});
}

private getLayers() {
const specLayers = [];
if (this.configurationOptions.layers) {
this.configurationOptions.layers.forEach(path => {
const layer = require(path);
specLayers.push(layer);
});
}
if (this.spec?.layers) {
Object.keys(this.spec.layers).forEach(layerName => {
const info = this.spec.layers[layerName];
if (!info?.path) {
return;
}
const [type, path] = info.path.split(':');
if (type === 'npm') {
const layer = require(path);
specLayers.push(layer);
}
});
}
return specLayers;
}
}
1 change: 1 addition & 0 deletions packages-serverless/serverless-app/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface IServerlessApp extends IMidwayApplication {
export interface IServerlessAppOptions extends IConfigurationOptions {
port?: string | number;
initContext?: any;
layers?: string[];
}
4 changes: 4 additions & 0 deletions packages-serverless/serverless-app/src/platform.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
export const StarterMap = {
aliyun: ['@ali/serverless-fc-starter', '@midwayjs/serverless-fc-starter'],
tencent: ['@midwayjs/serverless-scf-trigger'],
gaia: ['@ali/serverless-gaia-starter'],
ginkgo: ['@ali/serverless-ginkgo-starter'],
};

export const TriggerMap = {
aliyun: ['@midwayjs/serverless-fc-trigger'],
tencent: ['@midwayjs/serverless-scf-trigger'],
gaia: ['@ali/serverless-gaia-trigger'],
ginkgo: ['@ali/serverless-ginkgo-trigger'],
};
2 changes: 1 addition & 1 deletion packages-serverless/serverless-app/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const output404 = (path, functionsMap) => {
<div style="padding: 48px 24px 0 24px;font-size: 24px;color: #333;line-height: 24px;">404</div>
<div style="padding: 0 24px;font-size: 14px;color: #666;line-height: 48px;">path '${path}' not found</div>
${
allPath.length
process.env.NODE_ENV === 'development' && allPath.length
? `<div style="padding: 24px;font-size: 13px;line-height: 18px;">
<div>You can visit:</div>
${allPath
Expand Down

0 comments on commit 45cd7fe

Please sign in to comment.