diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml index f8cdc934..f2777f10 100644 --- a/.github/workflows/deploy-main.yml +++ b/.github/workflows/deploy-main.yml @@ -14,7 +14,6 @@ jobs: node-version: [18.16.0] steps: - - name: Checkout source code. uses: actions/checkout@v2 @@ -59,6 +58,8 @@ jobs: echo NODE_ENV=${{ secrets.NODE_ENV }} >> .env echo PROMPT_REDIS_KEY=${{ secrets.PROMPT_REDIS_KEY }} >> .env echo MAIN_SERVER=${{ secrets.MAIN_SERVER }} >> .env + echo SWAGGER_USER=${{ secrets.SWAGGER_USER }} >> .env + echo SWAGGER_PASSWORD=${{ secrets.SWAGGER_PASSWORD }} >> .env - name: build server files working-directory: ./ @@ -80,4 +81,4 @@ jobs: run: aws s3 cp --region ap-northeast-2 ./${{ env.GITHUB_SHA }}.zip s3://insightout-prod-s3/deploy/ - name: deploy with AWS codeDeploy - run: aws deploy create-deployment --application-name insightout-prod --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name insight-out-prod-group --s3-location bucket=insightout-prod-s3,bundleType=zip,key=deploy/${{ env.GITHUB_SHA }}.zip \ No newline at end of file + run: aws deploy create-deployment --application-name insightout-prod --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name insight-out-prod-group --s3-location bucket=insightout-prod-s3,bundleType=zip,key=deploy/${{ env.GITHUB_SHA }}.zip diff --git a/package.json b/package.json index ebac689a..d49bce97 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "cookie-parser": "^1.4.6", "dayjs": "^1.11.7", "dotenv-cli": "^7.2.1", + "express-basic-auth": "^1.2.1", "firebase-admin": "^11.8.0", "google-auth-library": "^8.8.0", "hanspell": "^0.9.7", diff --git a/src/apps/server/main.ts b/src/apps/server/main.ts index 00290089..8b44ec3b 100644 --- a/src/apps/server/main.ts +++ b/src/apps/server/main.ts @@ -6,6 +6,7 @@ import { EnvService } from '📚libs/modules/env/env.service'; import { AppModule } from './app.module'; import cookieParser from 'cookie-parser'; import { swaggerDescriptionMd } from '🔥apps/server/common/markdowns/swagger-description.markdown'; +import basicAuth from 'express-basic-auth'; async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -16,6 +17,13 @@ async function bootstrap() { const envService = app.get(EnvService); const PORT = +envService.get(EnvEnum.PORT) || 3000; + app.use( + basicAuth({ + users: { [envService.get(EnvEnum.SWAGGER_USER)]: envService.get(EnvEnum.SWAGGER_PASSWORD) }, + challenge: true, + }), + ); + const config = new DocumentBuilder() .setTitle('13기 4팀 서버') .setDescription(swaggerDescriptionMd) diff --git a/src/libs/modules/env/env.enum.ts b/src/libs/modules/env/env.enum.ts index c2bcc855..010f02af 100644 --- a/src/libs/modules/env/env.enum.ts +++ b/src/libs/modules/env/env.enum.ts @@ -65,4 +65,8 @@ export enum EnvEnum { // redis key PROMPT_REDIS_KEY, + + // swagger + SWAGGER_USER, + SWAGGER_PASSWORD, } diff --git a/yarn.lock b/yarn.lock index 6d95200b..8a4e77a0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2035,6 +2035,13 @@ base64-js@^1.3.0, base64-js@^1.3.1: resolved "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz" integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== +basic-auth@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a" + integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg== + dependencies: + safe-buffer "5.1.2" + bcrypt-pbkdf@^1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz" @@ -2988,6 +2995,13 @@ expect@^29.0.0, expect@^29.5.0: jest-message-util "^29.5.0" jest-util "^29.5.0" +express-basic-auth@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/express-basic-auth/-/express-basic-auth-1.2.1.tgz#d31241c03a915dd55db7e5285573049cfcc36381" + integrity sha512-L6YQ1wQ/mNjVLAmK3AG1RK6VkokA1BIY6wmiH304Xtt/cLTps40EusZsU1Uop+v9lTDPxdtzbFmdXfFO3KEnwA== + dependencies: + basic-auth "^2.0.1" + express@4.18.2: version "4.18.2" resolved "https://registry.npmjs.org/express/-/express-4.18.2.tgz" @@ -5647,16 +5661,16 @@ rxjs@^7.2.0, rxjs@^7.5.5: dependencies: tslib "^2.1.0" +safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: + version "5.1.2" + resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz" + integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== + safe-buffer@5.2.1, safe-buffer@>=5.1.0, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@~5.2.0: version "5.2.1" resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz" integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== -safe-buffer@~5.1.0, safe-buffer@~5.1.1: - version "5.1.2" - resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz" - integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== - safe-stable-stringify@^2.3.1: version "2.4.3" resolved "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz"