Skip to content

Commit

Permalink
chore: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
yugasun committed Jan 11, 2021
1 parent 4230ea9 commit e0484f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions example/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module NodeJS {
interface Global {
__NEST_APP__: any;
}
}
18 changes: 13 additions & 5 deletions example/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import { join } from 'path';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.enableCors();
app.setBaseViewsDir(join(__dirname, '..', 'views'));
app.setViewEngine('hbs');
// 缓存 Nest.js 实例
if (!global.__NEST_APP__) {
console.log('Initializing Nest.js Application');

return app;
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.enableCors();
app.setBaseViewsDir(join(__dirname, '..', 'views'));
app.setViewEngine('hbs');

global.__NEST_APP__ = app;
return app;
} else {
return global.__NEST_APP__;
}
}

// TODO: 通过注入 NODE_ENV 为 local,来方便本地启动服务,进行开发调试
Expand Down

0 comments on commit e0484f9

Please sign in to comment.