Browse Source

feat: disable controllers for worker

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5711/head
mertmit 2 years ago
parent
commit
dcba4957e7
  1. 25
      packages/nocodb/src/main.ts
  2. 20
      packages/nocodb/src/modules/datas/datas.module.ts
  3. 6
      packages/nocodb/src/modules/jobs/jobs.module.ts
  4. 68
      packages/nocodb/src/modules/metas/metas.module.ts
  5. 4
      packages/nocodb/src/modules/test/test.module.ts
  6. 4
      packages/nocodb/src/modules/users/users.module.ts
  7. 78
      packages/nocodb/src/worker.module.ts

25
packages/nocodb/src/main.ts

@ -2,15 +2,26 @@ import { NestFactory } from '@nestjs/core';
import cors from 'cors';
import express from 'express';
import { AppModule } from './app.module';
import { AppModule as WorkerModule } from './worker.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use(express.json({ limit: process.env.NC_REQUEST_BODY_SIZE || '50mb' }));
app.use(
cors({
exposedHeaders: 'xc-db-response',
}),
);
await app.listen(8080);
if (!process.env['NC_WORKER_CONTAINER']) {
app.use(
express.json({ limit: process.env.NC_REQUEST_BODY_SIZE || '50mb' }),
);
app.use(
cors({
exposedHeaders: 'xc-db-response',
}),
);
await app.listen(8080);
} else {
if (!process.env['NC_REDIS_URL']) {
throw new Error('NC_REDIS_URL is required');
}
const app = await NestFactory.create(WorkerModule);
await app.init();
}
}
bootstrap();

20
packages/nocodb/src/modules/datas/datas.module.ts

@ -27,14 +27,18 @@ import { PublicDatasService } from '../../services/public-datas.service';
}),
],
controllers: [
DatasController,
BulkDataAliasController,
DataAliasController,
DataAliasNestedController,
DataAliasExportController,
OldDatasController,
PublicDatasController,
PublicDatasExportController,
...(!process.env['NC_WORKER_CONTAINER']
? [
DatasController,
BulkDataAliasController,
DataAliasController,
DataAliasNestedController,
DataAliasExportController,
OldDatasController,
PublicDatasController,
PublicDatasExportController,
]
: []),
],
providers: [
DatasService,

6
packages/nocodb/src/modules/jobs/jobs.module.ts

@ -24,7 +24,11 @@ import { AtImportProcessor } from './at-import/at-import.processor';
name: JOBS_QUEUE,
}),
],
controllers: [DuplicateController, AtImportController],
controllers: [
...(!process.env['NC_WORKER_CONTAINER']
? [DuplicateController, AtImportController]
: []),
],
providers: [
QueueService,
JobsGateway,

68
packages/nocodb/src/modules/metas/metas.module.ts

@ -83,38 +83,42 @@ import { ProjectUsersService } from '../../services/project-users/project-users.
GlobalModule,
],
controllers: [
ApiDocsController,
ApiTokensController,
AttachmentsController,
AuditsController,
BasesController,
CachesController,
ColumnsController,
FiltersController,
FormColumnsController,
FormsController,
GalleriesController,
GridColumnsController,
GridsController,
HooksController,
KanbansController,
MapsController,
MetaDiffsController,
ModelVisibilitiesController,
OrgLcenseController,
OrgTokensController,
OrgUsersController,
PluginsController,
ProjectUsersController,
ProjectsController,
PublicMetasController,
ViewsController,
ViewColumnsController,
UtilsController,
TablesController,
SyncController,
SortsController,
SharedBasesController,
...(!process.env['NC_WORKER_CONTAINER']
? [
ApiDocsController,
ApiTokensController,
AttachmentsController,
AuditsController,
BasesController,
CachesController,
ColumnsController,
FiltersController,
FormColumnsController,
FormsController,
GalleriesController,
GridColumnsController,
GridsController,
HooksController,
KanbansController,
MapsController,
MetaDiffsController,
ModelVisibilitiesController,
OrgLcenseController,
OrgTokensController,
OrgUsersController,
PluginsController,
ProjectUsersController,
ProjectsController,
PublicMetasController,
ViewsController,
ViewColumnsController,
UtilsController,
TablesController,
SyncController,
SortsController,
SharedBasesController,
]
: []),
],
providers: [
ApiDocsService,

4
packages/nocodb/src/modules/test/test.module.ts

@ -2,6 +2,8 @@ import { Module } from '@nestjs/common';
import { TestController } from '../../controllers/test/test.controller';
@Module({
controllers: [TestController],
controllers: [
...(!process.env['NC_WORKER_CONTAINER'] ? [TestController] : []),
],
})
export class TestModule {}

4
packages/nocodb/src/modules/users/users.module.ts

@ -10,7 +10,9 @@ import { UsersController } from '../../controllers/users/users.controller';
@Module({
imports: [GlobalModule, PassportModule],
controllers: [UsersController],
controllers: [
...(!process.env['NC_WORKER_CONTAINER'] ? [UsersController] : []),
],
providers: [UsersService, GoogleStrategyProvider],
exports: [UsersService],
})

78
packages/nocodb/src/worker.module.ts

@ -0,0 +1,78 @@
import { Inject, Module, RequestMethod } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { BullModule } from '@nestjs/bull';
import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter';
import { Connection } from './connection/connection';
import { GlobalExceptionFilter } from './filters/global-exception/global-exception.filter';
import NcPluginMgrv2 from './helpers/NcPluginMgrv2';
import { DatasModule } from './modules/datas/datas.module';
import { IEventEmitter } from './modules/event-emitter/event-emitter.interface';
import { EventEmitterModule } from './modules/event-emitter/event-emitter.module';
import { AuthService } from './services/auth.service';
import { UsersModule } from './modules/users/users.module';
import { MetaService } from './meta/meta.service';
import Noco from './Noco';
import { TestModule } from './modules/test/test.module';
import { GlobalModule } from './modules/global/global.module';
import { HookHandlerService } from './services/hook-handler.service';
import { LocalStrategy } from './strategies/local.strategy';
import { AuthTokenStrategy } from './strategies/authtoken.strategy/authtoken.strategy';
import { BaseViewStrategy } from './strategies/base-view.strategy/base-view.strategy';
import { MetasModule } from './modules/metas/metas.module';
import NocoCache from './cache/NocoCache';
import { JobsModule } from './modules/jobs/jobs.module';
import type { OnApplicationBootstrap } from '@nestjs/common';
@Module({
imports: [
GlobalModule,
UsersModule,
...(process.env['PLAYWRIGHT_TEST'] === 'true' ? [TestModule] : []),
MetasModule,
DatasModule,
EventEmitterModule,
JobsModule,
NestJsEventEmitter.forRoot(),
...(process.env['NC_REDIS_URL']
? [
BullModule.forRoot({
url: process.env.NC_REDIS_URL,
}),
]
: []),
],
controllers: [],
providers: [
AuthService,
{
provide: APP_FILTER,
useClass: GlobalExceptionFilter,
},
LocalStrategy,
AuthTokenStrategy,
BaseViewStrategy,
HookHandlerService,
],
})
export class AppModule implements OnApplicationBootstrap {
constructor(
private readonly connection: Connection,
private readonly metaService: MetaService,
@Inject('IEventEmitter') private readonly eventEmitter: IEventEmitter,
) {}
// app init
async onApplicationBootstrap(): Promise<void> {
process.env.NC_VERSION = '0105004';
await NocoCache.init();
// todo: remove
// temporary hack
Noco._ncMeta = this.metaService;
Noco.config = this.connection.config;
Noco.eventEmitter = this.eventEmitter;
await NcPluginMgrv2.init(Noco.ncMeta);
}
}
Loading…
Cancel
Save