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

Commit

Permalink
fix: fix fc http trigger header
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed May 1, 2020
1 parent ffceb65 commit 3e80468
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
60 changes: 50 additions & 10 deletions packages/faas/src/starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ import {
MidwayContainer,
MidwayRequestContainer,
REQUEST_OBJ_CTX_KEY,
IMidwayCoreApplication,
} from '@midwayjs/core';
import { APPLICATION_KEY, FUNC_KEY, LOGGER_KEY, PLUGIN_KEY, } from '@midwayjs/decorator';
import {
APPLICATION_KEY,
FUNC_KEY,
LOGGER_KEY,
PLUGIN_KEY,
} from '@midwayjs/decorator';
import SimpleLock from '@midwayjs/simple-lock';
import * as compose from 'koa-compose';

Expand All @@ -25,7 +31,7 @@ function isTypeScriptEnvironment() {
return TS_MODE_PROCESS_FLAG === 'true' || !!require.extensions['.ts'];
}

export class FaaSStarter implements IFaaSStarter {
export class FaaSStarter implements IFaaSStarter, IMidwayCoreApplication {
public baseDir: string;
public appDir: string;
protected defaultHandlerMethod = 'handler';
Expand All @@ -52,7 +58,7 @@ export class FaaSStarter implements IFaaSStarter {
this.globalConfig = options.config || {};
this.globalMiddleware = options.middleware || [];
this.logger = options.logger || console;
this.baseDir = this.getBaseDir();
this.baseDir = this.getFaaSBaseDir();
this.initializeContext = options.initializeContext || {};

this.loader = new ContainerLoader({
Expand All @@ -69,7 +75,11 @@ export class FaaSStarter implements IFaaSStarter {
configService.addObject(this.globalConfig);
}

protected addConfiguration(filePath: string, fileDir?: string, namespace?: string) {
protected addConfiguration(
filePath: string,
fileDir?: string,
namespace?: string
) {
if (!fileDir) {
fileDir = dirname(resolve(filePath));
}
Expand All @@ -84,7 +94,7 @@ export class FaaSStarter implements IFaaSStarter {
* use this.addConfiguration
*/
protected initConfiguration(filePath: string, fileDir?: string) {
this.addConfiguration(filePath, fileDir)
this.addConfiguration(filePath, fileDir);
}

/**
Expand All @@ -96,8 +106,8 @@ export class FaaSStarter implements IFaaSStarter {
// this.initConfiguration('./configuration', __dirname);
}

private getBaseDir() {
if (isTypeScriptEnvironment()) {
private getFaaSBaseDir() {
if (this.isTypeScriptMode()) {
return join(this.appDir, 'src');
} else {
return join(this.appDir, 'dist');
Expand Down Expand Up @@ -259,9 +269,7 @@ export class FaaSStarter implements IFaaSStarter {
);
}
if (!context.env) {
context.env = this.getApplicationContext()
.getEnvironmentService()
.getCurrentEnvironment();
context.env = this.getConfig();
}
if (!context.logger) {
context.logger = this.logger;
Expand Down Expand Up @@ -302,6 +310,38 @@ export class FaaSStarter implements IFaaSStarter {
public addGlobalMiddleware(mw) {
this.globalMiddleware.push(mw);
}

public isTypeScriptMode(): boolean {
return isTypeScriptEnvironment();
}

public getBaseDir(): string {
return this.baseDir;
}

public getAppDir(): string {
return this.appDir;
}

public getEnv(): string {
return this.getApplicationContext()
.getEnvironmentService()
.getCurrentEnvironment();
}

public getType(): string {
throw 'application';
}

public getConfig(key?: string) {
return this.getApplicationContext()
.getConfigService()
.getConfiguration(key);
}

public getLogger() {
return this.logger;
}
}

function covertId(cls, method) {
Expand Down
2 changes: 1 addition & 1 deletion packages/serverless-fc-trigger/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Response {

this.statusCode = 200;
this._headers = {
'Content-Type': ['application/json; charset=utf-8'],
'content-type': 'application/json; charset=utf-8',
};
this.typeSetted = false;
this.body = null;
Expand Down

0 comments on commit 3e80468

Please sign in to comment.