linkkf 수정3
This commit is contained in:
22
nest_api/anime-api/src/app.controller.spec.ts
Normal file
22
nest_api/anime-api/src/app.controller.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
12
nest_api/anime-api/src/app.controller.ts
Normal file
12
nest_api/anime-api/src/app.controller.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
17
nest_api/anime-api/src/app.module.ts
Normal file
17
nest_api/anime-api/src/app.module.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import config from './config/config';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
load: [config],
|
||||
isGlobal: true,
|
||||
}),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
8
nest_api/anime-api/src/app.service.ts
Normal file
8
nest_api/anime-api/src/app.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
14
nest_api/anime-api/src/config/config.ts
Normal file
14
nest_api/anime-api/src/config/config.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import * as yaml from 'js-yaml';
|
||||
import { join } from 'path';
|
||||
|
||||
const YAML_CONFIG_PROD = 'production.yaml';
|
||||
const YAML_CONFIG_DEV = 'development.yaml';
|
||||
|
||||
export default () => {
|
||||
return yaml.load(
|
||||
process.env.NODE_ENV === 'production'
|
||||
? readFileSync(join(__dirname, YAML_CONFIG_PROD), 'utf8')
|
||||
: readFileSync(join(__dirname, YAML_CONFIG_DEV), 'utf8'),
|
||||
) as Record<string, any>;
|
||||
};
|
||||
2
nest_api/anime-api/src/config/development.yaml
Normal file
2
nest_api/anime-api/src/config/development.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
server:
|
||||
port: 7070
|
||||
2
nest_api/anime-api/src/config/production.yaml
Normal file
2
nest_api/anime-api/src/config/production.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
server:
|
||||
port: 3003
|
||||
14
nest_api/anime-api/src/main.ts
Normal file
14
nest_api/anime-api/src/main.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
// const port = process.env.NODE_SERVER_PORT;
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
const configService = app.get(ConfigService);
|
||||
const port = configService.get('NODE_SERVER_PORT');
|
||||
await app.listen(port);
|
||||
Logger.log(`Application listening on port ${port}`);
|
||||
}
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user