Skip to content

Commit

Permalink
fix: server hostname args (#1196)
Browse files Browse the repository at this point in the history
* fix: server hostname args

* fix: server sts endpoint

* fix: oss default factory definition

* fix: lint
  • Loading branch information
czy88840616 authored Jul 31, 2021
1 parent 1681f42 commit b9d73f0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 23 deletions.
21 changes: 21 additions & 0 deletions packages/oss/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
const path = require('path');
const fs = require('fs');

process.env.MIDWAY_TS_MODE = 'true';
jest.setTimeout(30000);

const envFile = path.join(__dirname, '.env');
if (!fs.existsSync(envFile)) {
fs.writeFileSync(
envFile,
'ALI_SDK_OSS_REGION=oss-cn-beijing\n' +
'ALI_SDK_OSS_ENDPOINT=\n' +
'ALI_SDK_OSS_ID=\n' +
'ALI_SDK_OSS_SECRET=\n' +
'ALI_SDK_OSS_BUCKET=\n' +
'ALI_SDK_STS_ID=\n' +
'ALI_SDK_STS_SECRET=\n' +
'ALI_SDK_STS_BUCKET=\n' +
'ALI_SDK_STS_ROLE=\n' +
'ALI_SDK_STS_ENDPOINT=https://sts.aliyuncs.com\n'
);
console.log('please set oss ak in .env file');
}
2 changes: 1 addition & 1 deletion packages/oss/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function checkBucketConfig(config) {

@Provide()
@Scope(ScopeEnum.Singleton)
export class OSSServiceFactory<T = OSS | OSS.STS> extends ServiceFactory<T> {
export class OSSServiceFactory<T = OSS> extends ServiceFactory<T> {
@Config('oss')
ossConfig;

Expand Down
3 changes: 3 additions & 0 deletions packages/oss/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ describe('/test/index.test.ts', () => {

const roleArn = require('./sts_config').roleArn;
const client1 = ossServiceFactory.get<OSSSTSService>('client1');
const client2 = ossServiceFactory.get('client2');

expect(client2.put).toBeDefined();

const result = await client1.assumeRole(roleArn);
expect((result as any).res.status).toEqual(200);
Expand Down
2 changes: 1 addition & 1 deletion packages/oss/test/sts_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export = {
accessKeySecret: process.env.ALI_SDK_STS_SECRET,
roleArn: process.env.ALI_SDK_STS_ROLE,
bucket: process.env.ALI_SDK_STS_BUCKET,
// endpoint: process.env.TRAVIS ? 'https://sts.us-west-1.aliyuncs.com/' : null,
endpoint: process.env.ALI_SDK_STS_ENDPOINT,
};
16 changes: 9 additions & 7 deletions packages/web-express/src/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ export class MidwayExpressFramework extends BaseFramework<
public async run(): Promise<void> {
if (this.configurationOptions.port) {
new Promise<void>(resolve => {
this.server.listen(
this.configurationOptions.port,
this.configurationOptions.hostname || '127.0.0.1',
() => {
resolve();
}
);
const args: any[] = [this.configurationOptions.port];
if (this.configurationOptions.hostname) {
args.push(this.configurationOptions.hostname);
}
args.push(() => {
resolve();
});

this.server.listen(...args);
});
}
}
Expand Down
15 changes: 8 additions & 7 deletions packages/web-koa/src/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,14 @@ export class MidwayKoaFramework extends MidwayKoaBaseFramework<
public async run(): Promise<void> {
if (this.configurationOptions.port) {
new Promise<void>(resolve => {
this.server.listen(
this.configurationOptions.port,
this.configurationOptions.hostname || '127.0.0.1',
() => {
resolve();
}
);
const args: any[] = [this.configurationOptions.port];
if (this.configurationOptions.hostname) {
args.push(this.configurationOptions.hostname);
}
args.push(() => {
resolve();
});
this.server.listen(...args);
});
}
}
Expand Down
15 changes: 8 additions & 7 deletions packages/web/src/framework/singleProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ export class MidwayWebSingleProcessFramework

if (this.configurationOptions.port) {
new Promise<void>(resolve => {
this.server.listen(
this.configurationOptions.port,
this.configurationOptions.hostname || '127.0.0.1',
() => {
resolve();
}
);
const args: any[] = [this.configurationOptions.port];
if (this.configurationOptions.hostname) {
args.push(this.configurationOptions.hostname);
}
args.push(() => {
resolve();
});
this.server.listen(...args);
});
}
}
Expand Down

0 comments on commit b9d73f0

Please sign in to comment.