@nestjs/core#HttpAdapterHost TypeScript Examples
The following examples show how to use
@nestjs/core#HttpAdapterHost.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: tenancy-core.module.ts From nestjs-tenancy with MIT License | 6 votes |
/**
* Create tenant context provider
*
* @private
* @static
* @returns {Provider}
* @memberof TenancyCoreModule
*/
private static createTenantContextProvider(): Provider {
return {
provide: TENANT_CONTEXT,
scope: Scope.REQUEST,
useFactory: (
req: Request,
moduleOptions: TenancyModuleOptions,
adapterHost: HttpAdapterHost,
) => this.getTenant(req, moduleOptions, adapterHost),
inject: [
REQUEST,
TENANT_MODULE_OPTIONS,
DEFAULT_HTTP_ADAPTER_HOST,
]
}
}
Example #2
Source File: social-auth.service.ts From nestjs-angular-starter with MIT License | 6 votes |
constructor(
@Inject('SOCIAL_AUTH_MODULE_CONFIG') private config: SocialAuthModuleConfig,
adapterHost: HttpAdapterHost,
) {
// Don't do anything on test as there is not instance of express
if (appConfig.ENVIRONMENT === 'test') return;
let expressApp: Application;
try {
// Get the express app in order to initialize social authentication
expressApp = adapterHost.httpAdapter.getInstance() as Application;
} catch (error) {
// Fail with an error but continue
Logger.error(error);
}
if (!expressApp)
// TODO: This should throw an error instead
Logger.warn(
"Social authentication is not supported, couldn't get handle of express!",
);
else {
// Now initialize the social authentication
this.init(expressApp);
}
}
Example #3
Source File: tenancy-core.module.ts From nestjs-tenancy with MIT License | 6 votes |
/**
* Check if the adapter is a fastify instance or not
*
* @private
* @static
* @param {HttpAdapterHost} adapterHost
* @returns {boolean}
* @memberof TenancyCoreModule
*/
private static adapterIsFastify(adapterHost: HttpAdapterHost): boolean {
return adapterHost.httpAdapter.getType() === 'fastify';
}
Example #4
Source File: tenancy-core.module.ts From nestjs-tenancy with MIT License | 6 votes |
/**
* Create Http Adapter provider
*
* @private
* @static
* @returns {Provider}
* @memberof TenancyCoreModule
*/
private static createHttpAdapterProvider(): Provider {
return {
provide: DEFAULT_HTTP_ADAPTER_HOST,
useFactory: (adapterHost: HttpAdapterHost) => adapterHost,
inject: [
HttpAdapterHost
],
};
}
Example #5
Source File: serve-static.provider.ts From adminjs-nestjs with MIT License | 6 votes |
serveStaticProvider: Provider = {
provide: AbstractLoader,
useFactory: (httpAdapterHost: HttpAdapterHost) => {
if (!httpAdapterHost || !httpAdapterHost.httpAdapter) {
return new NoopLoader();
}
const httpAdapter = httpAdapterHost.httpAdapter;
if (
httpAdapter &&
httpAdapter.constructor &&
httpAdapter.constructor.name === 'FastifyAdapter'
) {
// Not handled right now
return new NoopLoader();
}
return new ExpressLoader();
},
inject: [HttpAdapterHost],
}
Example #6
Source File: mercurius.module.ts From nestjs-mercurius with MIT License | 6 votes |
constructor(
private readonly graphqlFactory: GraphQLFactory,
private readonly graphqlTypesLoader: GraphQLTypesLoader,
@Inject(GRAPHQL_MODULE_OPTIONS)
protected readonly options: MercuriusModuleOptions,
protected readonly applicationConfig: ApplicationConfig,
protected readonly httpAdapterHost: HttpAdapterHost,
protected readonly hookExplorerService: HookExplorerService,
) {
super(httpAdapterHost, applicationConfig, options, hookExplorerService);
}
Example #7
Source File: mercurius-gateway.module.ts From nestjs-mercurius with MIT License | 6 votes |
constructor(
protected readonly httpAdapterHost: HttpAdapterHost,
protected readonly applicationConfig: ApplicationConfig,
@Inject(GRAPHQL_GATEWAY_MODULE_OPTIONS)
protected readonly options: MercuriusGatewayModuleOptions,
protected readonly hookExplorerService: HookExplorerService,
) {
super(httpAdapterHost, applicationConfig, options, hookExplorerService);
}
Example #8
Source File: admin.module.ts From adminjs-nestjs with MIT License | 5 votes |
constructor(
private readonly httpAdapterHost: HttpAdapterHost,
private readonly loader: AbstractLoader,
@Inject(CONFIG_TOKEN)
private readonly adminModuleOptions: AdminModuleOptions,
) {}
Example #9
Source File: create-test-client.ts From nestjs-mercurius with MIT License | 5 votes |
export function createTestClient(
testingModule: TestingModule,
): ReturnType<typeof createMercuriusTestClient> {
const httpAdapterHost = testingModule.get(HttpAdapterHost);
const app = httpAdapterHost.httpAdapter.getInstance();
return createMercuriusTestClient(app);
}
Example #10
Source File: tenancy-core.module.ts From nestjs-tenancy with MIT License | 5 votes |
/**
* Get Tenant id from the request
*
* @private
* @static
* @param {Request} req
* @param {TenancyModuleOptions} moduleOptions
* @param {HttpAdapterHost} adapterHost
* @returns {string}
* @memberof TenancyCoreModule
*/
private static getTenant(
req: Request,
moduleOptions: TenancyModuleOptions,
adapterHost: HttpAdapterHost,
): string {
// Check if the adaptor is fastify
const isFastifyAdaptor = this.adapterIsFastify(adapterHost);
if (!moduleOptions) {
throw new BadRequestException(`Tenant options are mandatory`);
}
// Extract the tenant idetifier
const {
tenantIdentifier = null,
isTenantFromSubdomain = false,
} = moduleOptions;
// Pull the tenant id from the subdomain
if (isTenantFromSubdomain) {
return this.getTenantFromSubdomain(isFastifyAdaptor, req);
} else {
// Validate if tenant identifier token is present
if (!tenantIdentifier) {
throw new BadRequestException(`${tenantIdentifier} is mandatory`);
}
return this.getTenantFromRequest(isFastifyAdaptor, req, tenantIdentifier);
}
}
Example #11
Source File: base-mercurius.module.ts From nestjs-mercurius with MIT License | 5 votes |
constructor(
protected readonly httpAdapterHost: HttpAdapterHost,
protected readonly applicationConfig: ApplicationConfig,
protected readonly options: Opts,
protected readonly hookExplorerService: HookExplorerService,
) {}
Example #12
Source File: pub-sub-host.ts From nestjs-mercurius with MIT License | 5 votes |
constructor(private readonly httpAdapterHost: HttpAdapterHost) {}
Example #13
Source File: auth.module.ts From relate with GNU General Public License v3.0 | 5 votes |
constructor(
@Inject(HttpAdapterHost) private readonly httpAdapterHost: HttpAdapterHost,
@Inject(AuthService) private readonly loader: AuthService,
) {}
Example #14
Source File: extension.module.ts From relate with GNU General Public License v3.0 | 5 votes |
constructor(
@Inject(HttpAdapterHost) private readonly httpAdapterHost: HttpAdapterHost,
@Inject(AppsService) private readonly loader: AppsService,
) {}
Example #15
Source File: files.module.ts From relate with GNU General Public License v3.0 | 5 votes |
constructor(
@Inject(HttpAdapterHost) private readonly httpAdapterHost: HttpAdapterHost,
@Inject(FilesService) private readonly loader: FilesService,
) {}
Example #16
Source File: health.module.ts From relate with GNU General Public License v3.0 | 5 votes |
constructor(
@Inject(HttpAdapterHost) private readonly httpAdapterHost: HttpAdapterHost,
@Inject(HealthService) private readonly loader: HealthService,
) {}
Example #17
Source File: web.module.ts From relate with GNU General Public License v3.0 | 5 votes |
constructor(
@Inject(GraphQLSchemaHost) private readonly schemaHost: GraphQLSchemaHost,
@Inject(HttpAdapterHost) private readonly httpAdapterHost: HttpAdapterHost,
) {}