Skip to content

Commit 5f3066a

Browse files
Auto stash before merge of "master" and "origin/master"
1 parent b6a36d2 commit 5f3066a

7 files changed

Lines changed: 25 additions & 12 deletions

File tree

lib/core/injector/container.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import { Metatype } from '@nestjs/common/interfaces/metatype.interface';
55
import { Module } from './module';
66
import { DynamicModule } from '@nestjs/common';
77
import { ModulesContainer } from './modules-container';
8+
import { ApplicationConfig } from './../application-config';
89
export declare class NestContainer {
10+
private readonly _applicationConfig;
911
private readonly globalModules;
1012
private readonly modules;
1113
private readonly dynamicModulesMetadata;
1214
private readonly moduleTokenFactory;
1315
private applicationRef;
16+
constructor(_applicationConfig?: ApplicationConfig);
17+
readonly applicationConfig: ApplicationConfig | undefined;
1418
setApplicationRef(applicationRef: any): void;
1519
getApplicationRef(): any;
1620
addModule(metatype: NestModuleMetatype | DynamicModule, scope: NestModuleMetatype[]): void;

lib/core/injector/container.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ const module_token_factory_1 = require("./module-token-factory");
1717
const invalid_module_exception_1 = require("./../errors/exceptions/invalid-module.exception");
1818
const modules_container_1 = require("./modules-container");
1919
class NestContainer {
20-
constructor() {
20+
constructor(_applicationConfig = void 0) {
21+
this._applicationConfig = _applicationConfig;
2122
this.globalModules = new Set();
2223
this.modules = new modules_container_1.ModulesContainer();
2324
this.dynamicModulesMetadata = new Map();
2425
this.moduleTokenFactory = new module_token_factory_1.ModuleTokenFactory();
2526
}
27+
get applicationConfig() {
28+
return this._applicationConfig;
29+
}
2630
setApplicationRef(applicationRef) {
2731
this.applicationRef = applicationRef;
2832
}

lib/core/injector/module.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export declare type CustomValue = CustomComponent & {
1919
};
2020
export declare type ComponentMetatype = Metatype<Injectable> | CustomFactory | CustomValue | CustomClass;
2121
export declare class Module {
22-
private _metatype;
23-
private _scope;
22+
private readonly _metatype;
23+
private readonly _scope;
2424
private _relatedModules;
2525
private _components;
2626
private _injectables;

lib/core/injector/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Module {
9696
name: external_context_creator_1.ExternalContextCreator.name,
9797
metatype: external_context_creator_1.ExternalContextCreator,
9898
isResolved: true,
99-
instance: new external_context_creator_1.ExternalContextCreator(new guards_context_creator_1.GuardsContextCreator(container), new guards_consumer_1.GuardsConsumer(), new interceptors_context_creator_1.InterceptorsContextCreator(container), new interceptors_consumer_1.InterceptorsConsumer(), container.getModules()),
99+
instance: new external_context_creator_1.ExternalContextCreator(new guards_context_creator_1.GuardsContextCreator(container, container.applicationConfig), new guards_consumer_1.GuardsConsumer(), new interceptors_context_creator_1.InterceptorsContextCreator(container, container.applicationConfig), new interceptors_consumer_1.InterceptorsConsumer(), container.getModules()),
100100
});
101101
}
102102
addModulesContainer(container) {

lib/core/nest-application.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ApplicationConfig } from './application-config';
77
import { NestContainer } from './injector/container';
88
import { NestApplicationContext } from './nest-application-context';
99
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
10+
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
1011
export declare class NestApplication extends NestApplicationContext implements INestApplication {
1112
private readonly express;
1213
private readonly config;
@@ -21,7 +22,7 @@ export declare class NestApplication extends NestApplicationContext implements I
2122
private readonly microservices;
2223
private isInitialized;
2324
constructor(container: NestContainer, express: any, config: ApplicationConfig, appOptions?: NestApplicationOptions);
24-
applyOptions(): any;
25+
applyOptions(): this;
2526
createServer(): any;
2627
setupModules(): Promise<void>;
2728
init(): Promise<this>;
@@ -38,7 +39,7 @@ export declare class NestApplication extends NestApplicationContext implements I
3839
set(...args: any[]): this;
3940
disable(...args: any[]): this;
4041
enable(...args: any[]): this;
41-
enableCors(): this;
42+
enableCors(options?: CorsOptions): this;
4243
listen(port: number | string, callback?: () => void): any;
4344
listen(port: number | string, hostname: string, callback?: () => void): any;
4445
listenAsync(port: number | string, hostname?: string): Promise<any>;

lib/core/nest-application.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
5353
this.routesResolver = new routes_resolver_1.RoutesResolver(container, express_adapter_1.ExpressAdapter, this.config);
5454
}
5555
applyOptions() {
56-
if (!this.appOptions) {
56+
if (!this.appOptions || !this.appOptions.cors) {
5757
return undefined;
5858
}
59-
this.appOptions.cors && this.enableCors();
59+
const isCorsOptionsObj = shared_utils_1.isObject(this.appOptions.cors);
60+
if (!isCorsOptionsObj) {
61+
return this.enableCors();
62+
}
63+
this.enableCors(this.appOptions.cors);
6064
}
6165
createServer() {
6266
if (this.appOptions && this.appOptions.httpsOptions) {
@@ -152,8 +156,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
152156
this.express.enable(...args);
153157
return this;
154158
}
155-
enableCors() {
156-
this.express.use(cors());
159+
enableCors(options) {
160+
this.express.use(cors(options));
157161
return this;
158162
}
159163
listen(port, ...args) {

lib/core/nest-factory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class NestFactoryStatic {
3333
const [expressInstance, appOptions] = isExpressInstance
3434
? [expressOrOptions, options]
3535
: [express_adapter_1.ExpressAdapter.create(), expressOrOptions];
36-
const container = new container_1.NestContainer();
3736
const applicationConfig = new application_config_1.ApplicationConfig();
37+
const container = new container_1.NestContainer(applicationConfig);
3838
this.applyLogger(appOptions);
3939
yield this.initialize(module, container, applicationConfig, expressInstance);
4040
return this.createNestInstance(new nest_application_1.NestApplication(container, expressInstance, applicationConfig, appOptions));
@@ -52,8 +52,8 @@ class NestFactoryStatic {
5252
if (!NestMicroservice) {
5353
throw new microservices_package_not_found_exception_1.MicroservicesPackageNotFoundException();
5454
}
55-
const container = new container_1.NestContainer();
5655
const applicationConfig = new application_config_1.ApplicationConfig();
56+
const container = new container_1.NestContainer(applicationConfig);
5757
this.applyLogger(options);
5858
yield this.initialize(module, container, applicationConfig);
5959
return this.createNestInstance(new NestMicroservice(container, options, applicationConfig));

0 commit comments

Comments
 (0)