Skip to content

Commit

Permalink
fix: support aliyun fc cors in local env (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar authored May 12, 2021
1 parent 2dcd5ef commit 245925a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages-serverless/serverless-app/src/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export class Framework

// 分析项目结构
const currentBaseDir = baseDir;
const platform = this.getPlatform();

const triggerMap = this.getTriggerMap();
const layers = this.getLayers();
Expand All @@ -235,6 +236,22 @@ export class Framework
this.app.use(bodyParser.urlencoded({ extended: false }));
this.app.use(bodyParser.json());
this.app.use((req, res, next) => {
// for ali fc
if (platform === 'aliyun') {
if (!this.spec.experimentalFeatures?.forceFCCORS) {
const origin = req.get('origin');
if (origin) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
if (req.method.toLowerCase() === 'options') {
res.send('');
return;
}
}
}
}
const gateway = createExpressGateway({
functionDir: appDir,
});
Expand Down

0 comments on commit 245925a

Please sign in to comment.