From 2d1ccf72643e761a4c7cf62343f530fdfea2559f Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Mon, 18 Oct 2021 12:11:30 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20CORS=20configuration=20in=20dock?= =?UTF-8?q?er-compose=20and=20Express?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 14 -------------- package.json | 1 + proxy.conf | 9 ++++----- src/server/index.ts | 9 ++++++++- yarn.lock | 2 +- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 822457d..cc0896a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,8 +12,6 @@ services: - "8050:8050" - "3050:3050" - "8051:8051" - extra_hosts: - - "host.docker.internal:host-gateway" depends_on: - rabbitmq - db @@ -32,8 +30,6 @@ services: container_name: comicvine-api ports: - "3080:3080" - extra_hosts: - - "host.docker.internal:host-gateway" environment: SERVICES: api env_file: ./docker-env/comicvine-service.env @@ -50,8 +46,6 @@ services: network: host image: frishi/comicvine-service container_name: comicvine-service - extra_hosts: - - "host.docker.internal:host-gateway" environment: SERVICES: comicvine volumes: @@ -66,8 +60,6 @@ services: network: host image: frishi/threetwo-import-service container_name: threetwo-import-api - extra_hosts: - - "host.docker.internal:host-gateway" ports: - "3000:3000" environment: @@ -88,8 +80,6 @@ services: network: host image: frishi/threetwo-import-service container_name: import - extra_hosts: - - "host.docker.internal:host-gateway" depends_on: - db - nats @@ -108,8 +98,6 @@ services: network: host image: frishi/threetwo-import-service container_name: image-transformation - extra_hosts: - - "host.docker.internal:host-gateway" volumes: - ./userdata:/threetwo-import-service/userdata - ./comics:/threetwo-import-service/comics @@ -141,8 +129,6 @@ services: nginx: image: nginx container_name: reverse-proxy - extra_hosts: - - "host.docker.internal:host-gateway" ports: - "80:80" volumes: diff --git a/package.json b/package.json index b234fe5..0c88a18 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "compromise-dates": "^2.2.1", "compromise-numbers": "^1.4.0", "compromise-sentences": "^0.3.0", + "cors": "^2.8.5", "dayjs": "^1.10.6", "ellipsize": "^0.1.0", "express": "^4.17.1", diff --git a/proxy.conf b/proxy.conf index 308283e..de4af9e 100644 --- a/proxy.conf +++ b/proxy.conf @@ -1,23 +1,22 @@ server { listen 8050; location / { - proxy_pass http://host.docker.internal:8050; + proxy_pass http://localhost:8050; } } - server { listen 3080; location /comicvine-service { - proxy_pass http://host.docker.internal:3080; + proxy_pass http://localhost:3080; } } server { listen 3000; - location /import { - proxy_pass http://host.docker.internal:3000; + location /import-service { + proxy_pass http://localhost:3000; } } \ No newline at end of file diff --git a/src/server/index.ts b/src/server/index.ts index e38d0f1..033e549 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -3,13 +3,20 @@ import bodyParser from "body-parser"; import { createServer } from "http"; import { Server } from "socket.io"; import router from "./route"; +import cors from "cors"; const amqp = require("amqplib/callback_api"); // call express const app: Express = express(); // define our app using express +app.use(cors({ origin: "*" })); const httpServer = createServer(); -export const io = new Server(httpServer, {}); +export const io = new Server(httpServer, { + cors: { + origin: "*", + methods: ["GET", "POST"], + } +}); // configure app to use bodyParser for // Getting data from body of requests diff --git a/yarn.lock b/yarn.lock index 801e87f..2ca6219 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4151,7 +4151,7 @@ core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== -cors@~2.8.5: +cors@^2.8.5, cors@~2.8.5: version "2.8.5" resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29" integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==