diff --git a/backend/config/local.yml b/backend/config/local.yml index 4b745e4..073360f 100644 --- a/backend/config/local.yml +++ b/backend/config/local.yml @@ -1,6 +1,10 @@ server: port: 5913 +client: + url: http://localhost + port: 8080 + db: url: localhost port: 27017 diff --git a/backend/config/release.yml b/backend/config/release.yml index 4abbcd0..ab846cc 100644 --- a/backend/config/release.yml +++ b/backend/config/release.yml @@ -1,6 +1,10 @@ server: port: 443 +client: + url: TBD + port: TBD + db: url: TBD port: 27017 diff --git a/backend/package-lock.json b/backend/package-lock.json index e6e2f3e..d9a1edc 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -113,6 +113,14 @@ "resolved": "https://registry.npmjs.org/@hapi/bourne/-/bourne-2.0.0.tgz", "integrity": "sha512-WEezM1FWztfbzqIUbsDzFRVMxSoLy3HugVcux6KDDtTqzPsLE8NDRHfXvev66aH1i2oOKKar3/XDjbvh/OUBdg==" }, + "@koa/cors": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@koa/cors/-/cors-3.1.0.tgz", + "integrity": "sha512-7ulRC1da/rBa6kj6P4g2aJfnET3z8Uf3SWu60cjbtxTA5g8lxRdX/Bd2P92EagGwwAhANeNw8T8if99rJliR6Q==", + "requires": { + "vary": "^1.1.2" + } + }, "@koa/router": { "version": "9.4.0", "resolved": "https://registry.npmjs.org/@koa/router/-/router-9.4.0.tgz", diff --git a/backend/package.json b/backend/package.json index 260f9ec..b166846 100755 --- a/backend/package.json +++ b/backend/package.json @@ -16,6 +16,7 @@ "author": "", "license": "ISC", "dependencies": { + "@koa/cors": "^3.1.0", "@koa/router": "^9.4.0", "@types/pino": "^6.3.4", "axios": "^0.19.2", diff --git a/backend/src/app/index.ts b/backend/src/app/index.ts index 07b11dc..0f45153 100755 --- a/backend/src/app/index.ts +++ b/backend/src/app/index.ts @@ -1,6 +1,7 @@ import 'reflect-metadata'; import Koa from 'koa'; import Router from '@koa/router'; +import cors from '@koa/cors'; import config from 'config'; import { Connection } from 'mongoose'; import { Server } from 'http'; @@ -29,8 +30,10 @@ const makeRouter = (apiRouterList: Router[]): Router => { }; const makeApp = (router: Router): Koa => { + const { url: clientUrl, port: clientPort } = config.get('client'); const app = new Koa(); app + .use(cors({ origin: `${clientUrl}:${clientPort}` })) .use(async (ctx, next) => { const { ip } = ctx.request; const rt = ctx.response.get('X-Response-Time');