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. 13
      packages/nocodb/src/main.ts
  2. 4
      packages/nocodb/src/modules/datas/datas.module.ts
  3. 6
      packages/nocodb/src/modules/jobs/jobs.module.ts
  4. 4
      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

13
packages/nocodb/src/main.ts

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

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

@ -27,6 +27,8 @@ import { PublicDatasService } from '../../services/public-datas.service';
}), }),
], ],
controllers: [ controllers: [
...(!process.env['NC_WORKER_CONTAINER']
? [
DatasController, DatasController,
BulkDataAliasController, BulkDataAliasController,
DataAliasController, DataAliasController,
@ -35,6 +37,8 @@ import { PublicDatasService } from '../../services/public-datas.service';
OldDatasController, OldDatasController,
PublicDatasController, PublicDatasController,
PublicDatasExportController, PublicDatasExportController,
]
: []),
], ],
providers: [ providers: [
DatasService, 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, name: JOBS_QUEUE,
}), }),
], ],
controllers: [DuplicateController, AtImportController], controllers: [
...(!process.env['NC_WORKER_CONTAINER']
? [DuplicateController, AtImportController]
: []),
],
providers: [ providers: [
QueueService, QueueService,
JobsGateway, JobsGateway,

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

@ -83,6 +83,8 @@ import { ProjectUsersService } from '../../services/project-users/project-users.
GlobalModule, GlobalModule,
], ],
controllers: [ controllers: [
...(!process.env['NC_WORKER_CONTAINER']
? [
ApiDocsController, ApiDocsController,
ApiTokensController, ApiTokensController,
AttachmentsController, AttachmentsController,
@ -115,6 +117,8 @@ import { ProjectUsersService } from '../../services/project-users/project-users.
SyncController, SyncController,
SortsController, SortsController,
SharedBasesController, SharedBasesController,
]
: []),
], ],
providers: [ providers: [
ApiDocsService, 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'; import { TestController } from '../../controllers/test/test.controller';
@Module({ @Module({
controllers: [TestController], controllers: [
...(!process.env['NC_WORKER_CONTAINER'] ? [TestController] : []),
],
}) })
export class TestModule {} export class TestModule {}

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

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