Skip to content

Commit 5f13d8b

Browse files
authored
Merge pull request #94 from boostcampwm-2024/feat-be-#86-main_server
[FEAT] host 페이지 요청에 따른 스트림키, 방송키 발급 api 메인 서버 구현
2 parents ddbef30 + 50828dc commit 5f13d8b

21 files changed

+5422
-239
lines changed

backend/mainServer/.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
/build
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
pnpm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# OS
16+
.DS_Store
17+
18+
# Tests
19+
/coverage
20+
/.nyc_output
21+
22+
# IDEs and editors
23+
/.idea
24+
.project
25+
.classpath
26+
.c9/
27+
*.launch
28+
.settings/
29+
*.sublime-workspace
30+
31+
# IDE - VSCode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json
37+
38+
# dotenv environment variable files
39+
.env
40+
.env.development.local
41+
.env.test.local
42+
.env.production.local
43+
.env.local
44+
45+
# temp directory
46+
.temp
47+
.tmp
48+
49+
# Runtime data
50+
pids
51+
*.pid
52+
*.seed
53+
*.pid.lock
54+
55+
# Diagnostic reports (https://nodejs.org/api/report.html)
56+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

backend/mainServer/README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<p align="center">
2+
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
3+
</p>
4+
5+
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6+
[circleci-url]: https://circleci.com/gh/nestjs/nest
7+
8+
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
9+
<p align="center">
10+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13+
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14+
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
15+
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
16+
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
17+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
18+
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
19+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
20+
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
21+
</p>
22+
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
23+
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
24+
25+
## Description
26+
27+
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
28+
29+
## Project setup
30+
31+
```bash
32+
$ yarn install
33+
```
34+
35+
## Compile and run the project
36+
37+
```bash
38+
# development
39+
$ yarn run start
40+
41+
# watch mode
42+
$ yarn run start:dev
43+
44+
# production mode
45+
$ yarn run start:prod
46+
```
47+
48+
## Run tests
49+
50+
```bash
51+
# unit tests
52+
$ yarn run test
53+
54+
# e2e tests
55+
$ yarn run test:e2e
56+
57+
# test coverage
58+
$ yarn run test:cov
59+
```
60+
61+
## Deployment
62+
63+
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
64+
65+
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
66+
67+
```bash
68+
$ yarn install -g mau
69+
$ mau deploy
70+
```
71+
72+
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
73+
74+
## Resources
75+
76+
Check out a few resources that may come in handy when working with NestJS:
77+
78+
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
79+
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
80+
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
81+
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
82+
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
83+
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
84+
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
85+
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
86+
87+
## Support
88+
89+
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
90+
91+
## Stay in touch
92+
93+
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
94+
- Website - [https://nestjs.com](https://nestjs.com/)
95+
- Twitter - [@nestframework](https://twitter.com/nestframework)
96+
97+
## License
98+
99+
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).

backend/mainServer/nest-cli.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"deleteOutDir": true
7+
}
8+
}

backend/mainServer/package.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "mainServer",
3+
"version": "0.0.1",
4+
"description": "",
5+
"author": "",
6+
"private": true,
7+
"license": "UNLICENSED",
8+
"scripts": {
9+
"build": "nest build",
10+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11+
"start": "nest start",
12+
"start:dev": "nest start --watch",
13+
"start:debug": "nest start --debug --watch",
14+
"start:prod": "node dist/main",
15+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
16+
"test": "jest",
17+
"test:watch": "jest --watch",
18+
"test:cov": "jest --coverage",
19+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
20+
"test:e2e": "jest --config ./test/jest-e2e.json"
21+
},
22+
"dependencies": {
23+
"@nestjs/common": "^10.0.0",
24+
"@nestjs/core": "^10.0.0",
25+
"@nestjs/platform-express": "^10.0.0",
26+
"reflect-metadata": "^0.2.0",
27+
"rxjs": "^7.8.1"
28+
},
29+
"devDependencies": {
30+
"@jest/globals": "^29.7.0",
31+
"@nestjs/cli": "^10.0.0",
32+
"@nestjs/schematics": "^10.0.0",
33+
"@nestjs/testing": "^10.0.0",
34+
"@types/express": "^5.0.0",
35+
"@types/jest": "^29.5.14",
36+
"@types/node": "^20.3.1",
37+
"@types/supertest": "^6.0.0",
38+
"@typescript-eslint/eslint-plugin": "^8.0.0",
39+
"@typescript-eslint/parser": "^8.0.0",
40+
"eslint": "^8.0.0",
41+
"eslint-config-prettier": "^9.0.0",
42+
"eslint-plugin-prettier": "^5.0.0",
43+
"jest": "^29.7.0",
44+
"prettier": "^3.0.0",
45+
"source-map-support": "^0.5.21",
46+
"supertest": "^7.0.0",
47+
"ts-jest": "^29.1.0",
48+
"ts-loader": "^9.4.3",
49+
"ts-node": "^10.9.1",
50+
"tsconfig-paths": "^4.2.0",
51+
"typescript": "^5.1.3"
52+
},
53+
"jest": {
54+
"moduleFileExtensions": [
55+
"js",
56+
"json",
57+
"ts"
58+
],
59+
"rootDir": "src",
60+
"testRegex": ".*\\.spec\\.ts$",
61+
"transform": {
62+
"^.+\\.(t|j)s$": "ts-jest"
63+
},
64+
"collectCoverageFrom": [
65+
"**/*.(t|j)s"
66+
],
67+
"coverageDirectory": "../coverage",
68+
"testEnvironment": "node"
69+
}
70+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { AppController } from './app.controller';
3+
import { AppService } from './app.service';
4+
5+
describe('AppController', () => {
6+
let appController: AppController;
7+
8+
beforeEach(async () => {
9+
const app: TestingModule = await Test.createTestingModule({
10+
controllers: [AppController],
11+
providers: [AppService],
12+
}).compile();
13+
14+
appController = app.get<AppController>(AppController);
15+
});
16+
17+
describe('root', () => {
18+
it('should return "Hello World!"', () => {
19+
expect(appController.getHello()).toBe('Hello World!');
20+
});
21+
});
22+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Controller, Get } from '@nestjs/common';
2+
import { AppService } from './app.service';
3+
4+
@Controller()
5+
export class AppController {
6+
constructor(private readonly appService: AppService) {}
7+
8+
@Get()
9+
getHello(): string {
10+
return this.appService.getHello();
11+
}
12+
}

backend/mainServer/src/app.module.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Module } from '@nestjs/common';
2+
import { AppController } from './app.controller';
3+
import { AppService } from './app.service';
4+
import { HostController } from './host/host.controller';
5+
import { HostService } from './host/host.service';
6+
7+
@Module({
8+
imports: [],
9+
controllers: [AppController, HostController],
10+
providers: [AppService, HostService],
11+
})
12+
export class AppModule {}

backend/mainServer/src/app.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Injectable } from '@nestjs/common';
2+
3+
@Injectable()
4+
export class AppService {
5+
getHello(): string {
6+
return 'Hello World!';
7+
}
8+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// host.controller.spec.ts
2+
import { Test, TestingModule } from '@nestjs/testing';
3+
import { HostController } from './host.controller';
4+
import { HostService } from './host.service';
5+
import { HttpStatus } from '@nestjs/common';
6+
import {describe, expect, jest} from '@jest/globals';
7+
import {Request, Response} from 'express';
8+
9+
describe('HostController', () => {
10+
let controller: HostController;
11+
let service: HostService;
12+
13+
beforeEach(async () => {
14+
const module: TestingModule = await Test.createTestingModule({
15+
controllers: [HostController],
16+
providers: [HostService],
17+
}).compile();
18+
19+
controller = module.get<HostController>(HostController);
20+
service = module.get<HostService>(HostService);
21+
});
22+
23+
it('should be defined', () => {
24+
expect(controller).toBeDefined();
25+
});
26+
27+
it('should return 200 with host data for valid request', async () => {
28+
const mockUuid = 'test-uuid';
29+
const mockHostData = `session-info-for-${mockUuid}`;
30+
31+
jest.spyOn(service, 'generateStreamKey').mockResolvedValue(mockHostData);
32+
33+
const req = {
34+
headers: {
35+
host: 'http://example.com',
36+
'content-type': 'application/json',
37+
},
38+
body: {
39+
uuid: mockUuid,
40+
},
41+
} as unknown as Request;
42+
43+
const res = {
44+
status: jest.fn().mockReturnThis(),
45+
json: jest.fn(),
46+
} as unknown as Response;
47+
48+
await controller.generateStreamKey(req, res);
49+
50+
expect(res.status).toHaveBeenCalledWith(HttpStatus.OK);
51+
expect(res.json).toHaveBeenCalledWith({ 'host-data': mockHostData });
52+
});
53+
54+
it('should return 400 for invalid request with missing uuid', async () => {
55+
jest.spyOn(service, 'generateStreamKey').mockResolvedValue(undefined);
56+
57+
const req = {
58+
headers: {
59+
host: 'http://example.com',
60+
'content-type': 'application/json',
61+
},
62+
body: {
63+
// uuid가 없는 비정상적인 요청
64+
},
65+
} as unknown as Request;
66+
67+
const res = {
68+
status: jest.fn().mockReturnThis(),
69+
json: jest.fn(),
70+
} as unknown as Response;
71+
72+
await controller.generateStreamKey(req, res);
73+
74+
expect(res.status).toHaveBeenCalledWith(HttpStatus.BAD_REQUEST);
75+
});
76+
77+
it('should return 400 for invalid request with incorrect content-type', async () => {
78+
jest.spyOn(service, 'generateStreamKey').mockResolvedValue(undefined);
79+
80+
const req = {
81+
headers: {
82+
host: 'http://example.com',
83+
'content-type': 'text/plain',
84+
},
85+
body: {
86+
uuid: 'test-uuid',
87+
},
88+
} as unknown as Request;
89+
90+
const res = {
91+
status: jest.fn().mockReturnThis(),
92+
json: jest.fn(),
93+
} as unknown as Response;
94+
95+
await controller.generateStreamKey(req, res);
96+
97+
expect(res.status).toHaveBeenCalledWith(HttpStatus.BAD_REQUEST);
98+
});
99+
});

0 commit comments

Comments
 (0)