This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { AppController } from './app.controller'; | |
import { ConfigModule } from './config/config.module'; | |
import { SearchModule } from './modules/search/search.module'; | |
import { MovieModule } from './modules/movie/movie.module'; | |
@Module({ | |
imports: [ConfigModule, SearchModule, MovieModule], | |
controllers: [AppController], | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get } from '@nestjs/common'; | |
@Controller() | |
export class AppController { | |
private start: number; | |
constructor() { | |
this.start = Date.now(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as dotenv from 'dotenv'; | |
import * as fs from 'fs'; | |
export class ConfigService { | |
private readonly envConfig: { [key: string]: string }; | |
constructor(filePath: string) { | |
this.envConfig = dotenv.parse(fs.readFileSync(filePath)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { ConfigService } from './config.service'; | |
@Module({ | |
providers: [ | |
{ | |
provide: ConfigService, | |
useValue: new ConfigService('.env'), | |
}, | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get, Query } from '@nestjs/common'; | |
import { MovieService } from './movie.service'; | |
@Controller() | |
export class MovieController { | |
constructor(public readonly movieService: MovieService) {} | |
@Get('movies') | |
async getMovies(@Query('search') search: string) { | |
if (search !== undefined && search.length > 1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { MovieService } from './movie.service'; | |
import { MovieController } from './movie.controller'; | |
import { SearchModule } from '../search/search.module'; | |
@Module({ | |
imports: [SearchModule], | |
providers: [MovieService], | |
controllers: [MovieController], | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@nestjs/common'; | |
import { SearchService } from '../search/search.service'; | |
@Injectable() | |
export class MovieService { | |
constructor(readonly esService: SearchService) {} | |
async findMovies(search: string = '') { | |
return await this.esService.search(search); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module, OnModuleInit } from '@nestjs/common'; | |
import { SearchService } from './search.service'; | |
import { ElasticsearchModule } from '@nestjs/elasticsearch'; | |
import { ConfigModule } from '../../config/config.module'; | |
import { ConfigService } from '../../config/config.service'; | |
@Module({ | |
imports: [ | |
ElasticsearchModule.registerAsync({ | |
imports: [ConfigModule], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@nestjs/common'; | |
import { ElasticsearchService } from '@nestjs/elasticsearch'; | |
import * as moviesJson from '../../../movies.json'; | |
import { ConfigService } from '../../config/config.service'; | |
interface MoviesJsonResponse { | |
title: string; | |
year: number; | |
cast: string[]; | |
genres: string[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NestFactory } from '@nestjs/core'; | |
import { AppModule } from './app.module'; | |
import { ConfigService } from './config/config.service'; | |
async function bootstrap() { | |
const configService = new ConfigService('.env'); | |
const app = await NestFactory.create(AppModule); | |
app.enableCors(); | |
app.setGlobalPrefix(configService.get('GLOBAL_PREFIX')); | |
await app.listen(configService.get('NODE_PORT')); |
OlderNewer