diff --git a/.env.sample b/.env.sample index 5a74326..e6c1905 100644 --- a/.env.sample +++ b/.env.sample @@ -8,9 +8,10 @@ DB_FOLDER='/mnt/hdd/videos/db' RECENT_SEARCHES_FOLDER="/mnt/hdd/videos/recent-searches" #actual env variables starts here +NODE_ENV=production PORT=3000 LOG_FILE_REQUESTS_NAME="static_log.txt" -DB_FILENAME="db.db" +DB_FILENAME="db.sqlite" RECENT_SEARCHES_LIMIT=20 PATTERNS_TO_IGNORE='["AOE1/"]' #file path patterns to ignore from video files scan, must be in json format diff --git a/Dockerfile b/Dockerfile index 3cf57bc..2657bd9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,6 @@ RUN npm run typeorm:run-migrations EXPOSE $PORT -# serve dev -CMD ["npm", "run", "start:dev"] +# start +CMD ["npm", "run", "start"] -#serve prod -#CMD ["npm", "run", "start"] diff --git a/package.json b/package.json index 85f04c2..14f11a3 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "prebuild": "rimraf dist", "build": "nest build && npm run copy-files", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "start": "nest start", + "start": "bash ./start.sh", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/src/main", diff --git a/src/RequestLog/request-log.middleware.ts b/src/RequestLog/request-log.middleware.ts index 28ceafc..13baf54 100644 --- a/src/RequestLog/request-log.middleware.ts +++ b/src/RequestLog/request-log.middleware.ts @@ -8,7 +8,9 @@ export class RequestLogMiddleware implements NestMiddleware { async use(req: Request, res: Response, next: NextFunction) { const strIP = this.extractIp(req); this.log(strIP + ' ' + req.method + ' ' + decodeURI(req.url)); - console.log(decodeURI(req.url)); + if (configService.isDev()) { + console.log(decodeURI(req.url)); + } next(); } diff --git a/src/Static/static.service.spec.ts b/src/Static/static.service.spec.ts deleted file mode 100644 index 8f3a8a7..0000000 --- a/src/Static/static.service.spec.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { StaticService } from './static.service'; - -describe('StaticService', () => { - let staticService: StaticService; - - beforeEach(() => { - staticService = new StaticService(); - }); - - describe('provideDirIndex', () => { - it('should return file/dir list of dir', async () => { - jest.spyOn(staticService, 'provideDirIndex'); - process.env.STATIC_SERVE_FOLDER = 'test/Static/_test-data/StaticServe'; - - const result = await staticService.provideDirIndex(''); - expect(result).toHaveLength(2); - }); - }); -}); diff --git a/src/config/config.service.ts b/src/config/config.service.ts index 716b55f..4444bbe 100644 --- a/src/config/config.service.ts +++ b/src/config/config.service.ts @@ -38,6 +38,10 @@ export class ConfigService { public getRecentSearchesConfig(): RecentSearchesConfig { return this.recentSearches; } + + public isDev(): boolean { + return this.getEnv('NODE_ENV') !== 'production'; + } } export const configService = new ConfigService(); diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..add5cb1 --- /dev/null +++ b/start.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ "$NODE_ENV" == "production" ]; then + echo "Starting app in production mode" + echo "Running prebuild" + npm run prebuild + echo "Running build" + npm run build + echo "Starting app" + npm run start:prod +else + echo "Starting app in development mode" + npm run start:dev +fi diff --git a/test/Static/_test-data/StaticServe/test-dir/test-file-2 b/test/Static/_test-data/StaticServe/test-dir/test-file-2 deleted file mode 100644 index e69de29..0000000 diff --git a/test/Static/_test-data/StaticServe/test-file b/test/Static/_test-data/StaticServe/test-file deleted file mode 100644 index e69de29..0000000 diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts deleted file mode 100644 index 0012dcd..0000000 --- a/test/app.e2e-spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; -import * as request from 'supertest'; -import { AppModule } from '../src/app.module'; - -describe('AppController (e2e)', () => { - let app: INestApplication; - - beforeEach(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication(); - await app.init(); - }); - - it('/ (GET)', () => { - return request(app.getHttpServer()) - .get('/') - .expect(200) - .expect('Hello World!'); - }); -}); diff --git a/test/jest-e2e.json b/test/jest-e2e.json deleted file mode 100644 index e9d912f..0000000 --- a/test/jest-e2e.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "moduleFileExtensions": ["js", "json", "ts"], - "rootDir": ".", - "testEnvironment": "node", - "testRegex": ".e2e-spec.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - } -}