Skip to content

Commit

Permalink
feat : 환경 변수를 통한 제어 구현
Browse files Browse the repository at this point in the history
- api 키를 환경변수로 등록
- production 환경일때는 https로, 개발환경인 경우 http로 동작하도록 구현

Co-authored-by: GeunH <[email protected]>
  • Loading branch information
LeeTH916 and GeunH committed Dec 3, 2023
1 parent ff52d89 commit f7fdeba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions be/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
import { AppModule } from "./app.module";
import { TransformInterceptor } from "./response.interceptor";
import { HttpExceptionFilter } from "./error.filter";
import * as fs from 'fs';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

let httpsOptions, app;
if(process.env.NODE_ENV==="PROD"){
httpsOptions = {
key: fs.readFileSync('/etc/letsencrypt/live/www.nibobnebob.site/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/www.nibobnebob.site/fullchain.pem'),
};

app = await NestFactory.create(AppModule, { httpsOptions });
} else {
app = await NestFactory.create(AppModule);
}
app.setGlobalPrefix("api");
app.useGlobalFilters(new HttpExceptionFilter());
app.useGlobalInterceptors(new TransformInterceptor());
Expand All @@ -20,4 +32,4 @@ async function bootstrap() {
SwaggerModule.setup("api", app, document);
await app.listen(8000);
}
bootstrap();
bootstrap();
4 changes: 2 additions & 2 deletions be/src/restaurant/restaurant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { UserRepository } from "src/user/user.repository";
import { ReviewRepository } from "src/review/review.repository";
import { LocationDto } from "./dto/location.dto";

const key = "api키 입력하세요";
const key = process.env.API_KEY;

@Injectable()
export class RestaurantService implements OnModuleInit {
onModuleInit() {
//this.updateRestaurantsFromSeoulData();
this.updateRestaurantsFromSeoulData();
setInterval(
() => {
this.updateRestaurantsFromSeoulData();
Expand Down

0 comments on commit f7fdeba

Please sign in to comment.