diff --git a/Dockerfile b/Dockerfile index 7091912..fa29105 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ FROM node:9.8.0 -RUN apt-get install git -COPY . /usr/api-server +COPY . /usr/api-server WORKDIR /usr/api-server + RUN npm install RUN npm install pm2 -g +RUN npm run prestart:prod EXPOSE 3000 -CMD ["pm2-runtime", "index.js", "--name", "api-server"] +CMD ["pm2-runtime", "dist/server.js", "--name", "api-server"] diff --git a/src/modules/data/data.controller.ts b/src/modules/data/data.controller.ts index 61f5896..1d2a82a 100644 --- a/src/modules/data/data.controller.ts +++ b/src/modules/data/data.controller.ts @@ -16,6 +16,14 @@ export class DataController { return this.backupService.execute() } + @Get('/has-been-initialized') + async hasBeenInitialized(): Promise { + const hasBeenInitialized = await this.initService.hasBeenInitialized(); + return Promise.resolve({ + hasBeenInitialized + }) + } + @Post('/init') init(@Body() body): Promise { return this.initService.initialize(body.force) diff --git a/src/modules/data/init.service.ts b/src/modules/data/init.service.ts index 9288691..1401e25 100644 --- a/src/modules/data/init.service.ts +++ b/src/modules/data/init.service.ts @@ -10,13 +10,22 @@ export class InitService { this.client = this.clientService.client } + async hasBeenInitialized(): Promise { + const masterScreenerExists = await this.client.indices.exists({ index: 'master_screener'}); + const questionsExists = await this.client.indices.exists({ index: 'questions'}); + const programsExists = await this.client.indices.exists({ index: 'programs'}); + + return masterScreenerExists && questionsExists && programsExists; + } + async initialize(force = false): Promise { const masterScreenerExists = await this.client.indices.exists({ index: 'master_screener'}); const questionsExists = await this.client.indices.exists({ index: 'questions'}); const programsExists = await this.client.indices.exists({ index: 'programs'}); - const hasBeenInitialized = masterScreenerExists || questionsExists || programsExists; + const hasBeenInitialized = masterScreenerExists && questionsExists && programsExists; + if (hasBeenInitialized && !force) { throw new Error("Database has already been initialized."); diff --git a/src/modules/data/upload.service.ts b/src/modules/data/upload.service.ts index 68a6511..90eb593 100644 --- a/src/modules/data/upload.service.ts +++ b/src/modules/data/upload.service.ts @@ -40,6 +40,7 @@ export class UploadService { body: { properties: { ...normalizedMapping } } }) } else { + console.dir(Object.keys(data)); throw new Error("No queryMappings") } if (data.queries) { diff --git a/src/server.ts b/src/server.ts index 7d304dc..0d344d5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -6,18 +6,11 @@ const bodyParser = require('body-parser'); const instance = express(); async function bootstrap() { - const app = await NestFactory.create(ApplicationModule, instance); - app.use(bodyParser.urlencoded({ - extended: true - })); - app.use(bodyParser.json()); - - instance.use(bodyParser.urlencoded({ - extended: true - })); - instance.use(bodyParser.json()); - - + instance.use(bodyParser.urlencoded( {extended: true} )); + instance.use(bodyParser.json( {limit: '50mb'} )); + const app = await NestFactory.create(ApplicationModule, instance); + app.use(bodyParser.urlencoded( {extended: true} )); + app.use(bodyParser.json( {limit: '50mb'} )); await app.listen(3000); } bootstrap();