Skip to content

Commit

Permalink
[#0] Allow CORS from the known FE client
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejin Jeon authored and 3jins committed Feb 16, 2021
1 parent 42f34a6 commit 41bb452
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/config/local.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
server:
port: 5913

client:
url: http://localhost
port: 8080

db:
url: localhost
port: 27017
Expand Down
4 changes: 4 additions & 0 deletions backend/config/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
server:
port: 443

client:
url: TBD
port: TBD

db:
url: TBD
port: 27017
Expand Down
8 changes: 8 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions backend/src/app/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 41bb452

Please sign in to comment.