Skip to content

Commit

Permalink
fix: set appDir before setServerEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Aug 16, 2018
1 parent 1d867ed commit 6b418ca
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions packages/midway-core/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class MidwayLoader extends EggLoader {
baseDir;
appDir;
options;
appInfo;

constructor(options: MidwayLoaderOptions) {
super(options);
Expand Down Expand Up @@ -94,15 +93,31 @@ export class MidwayLoader extends EggLoader {
}
}

getAppInfo() {
if (!this.appInfo) {
getEggPaths() {
if(!this.appDir) {
// register appDir here
this.registerTypescriptDirectory();
const appInfo = super.getAppInfo();
this.appInfo = Object.assign(appInfo, {
root: this.appDir
});
}
return this.appInfo;
return super.getEggPaths();
}

getServerEnv() {
let serverEnv;

const envPath = path.join(this.appDir, 'config/env');
if (fs.existsSync(envPath)) {
serverEnv = fs.readFileSync(envPath, 'utf8').trim();
}

if (!serverEnv) {
serverEnv = process.env.EGG_SERVER_ENV || process.env.MIDWAY_SERVER_ENV;
}

if (!serverEnv) {
serverEnv = super.getServerEnv();
}

return serverEnv;
}

private _buildLoadDir(baseDir, loadDir) {
Expand Down

0 comments on commit 6b418ca

Please sign in to comment.