From 5d79e66700017a97c343f5375996502b738b55a6 Mon Sep 17 00:00:00 2001 From: Devon Richards Date: Fri, 5 Jan 2024 10:42:15 -0600 Subject: [PATCH] feat(cors): Disable cors on the export routes. --- .docker/Dockerfile | 2 +- .docker/Dockerfile.jobs | 2 +- .docker/docker-compose.yml | 21 ++++++++++++--------- RELEASE_NOTES.md | 7 +++++++ flake.nix | 2 +- server/routes/cube/export.js | 26 +++++++++++++++++--------- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 5c6bb1d1b..9d3ad4f3b 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -7,7 +7,7 @@ ENV NODE_ENV=production RUN curl https://sdk.cloud.google.com > install.sh RUN bash install.sh --disable-prompts --install-dir=/root/ -ENV PATH $PATH:/root/google-cloud-sd --install-dir=/root/k/bin +ENV PATH $PATH:/root/google-cloud-sdk/ --install-dir=/root/bin RUN apt-get update && apt-get install -y gcc python3-dev python3-setuptools python3-pip python3-crcmod WORKDIR /CubeArtisan diff --git a/.docker/Dockerfile.jobs b/.docker/Dockerfile.jobs index d3ffea216..3c8771c57 100644 --- a/.docker/Dockerfile.jobs +++ b/.docker/Dockerfile.jobs @@ -7,7 +7,7 @@ ENV NODE_ENV=production RUN curl https://sdk.cloud.google.com > install.sh RUN bash install.sh --disable-prompts --install-dir=/root/ -ENV PATH $PATH:/root/google-cloud-sd --install-dir=/root/k/bin +ENV PATH $PATH:/root/google-cloud-sdk/ --install-dir=/root/bin RUN apt-get update && apt-get install -y gcc python3-dev python3-setuptools python3-pip python3-crcmod WORKDIR /CubeArtisan diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index 9d698d6d0..02f36bb3e 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -1,17 +1,15 @@ version: '3' services: cubeartisan-mongodb: - image: 'mongo:6.0.5' + image: 'mongo:4.4' + command: mongod --replSet rs0 volumes: - - cubeartisan-mongodb-volume:/data/db - ports: - - '27017-27019:27017-27019' + - cubeartisan-mongodb-volume2:/data/db + ports: [] cubeartisan-jobs: build: dockerfile: .docker/Dockerfile.jobs context: ../ - cache_from: - - ${REPOSITORY}/cubeartisan-jobs:latest image: ${REPOSITORY}/cubeartisan-jobs:${TAG} depends_on: - "cubeartisan-mongodb" @@ -19,15 +17,20 @@ services: build: dockerfile: .docker/Dockerfile context: ../ - cache_from: - - ${REPOSITORY}/cubeartisan-jobs:${TAG} args: REPOSITORY: ${REPOSITORY} TAG: ${TAG} + environment: + MONGODB_DBNAME: cubeartisan + MONGODB_HOST: cubeartisan-mongodb + MONGODB_PASSWORD: "" + MONGODB_PORT: 27017 + MONGODB_REPLICASET: rs0 + MONGODB_USER: "" image: ${REPOSITORY}/cubeartisan:${TAG} ports: - "5000:8080" depends_on: - "cubeartisan-mongodb" volumes: - cubeartisan-mongodb-volume: + cubeartisan-mongodb-volume2: diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d9679ac66..368a2e737 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -379,3 +379,10 @@ This release is composed of porting over bug fixes for bugs we carried over from #### Bug Fixes - Fix for specifying color category in csv import. + + +### v1.4.6.9 + +#### Features + +- Support CORS on the cube export routes diff --git a/flake.nix b/flake.nix index ccf711793..465166e06 100644 --- a/flake.nix +++ b/flake.nix @@ -9,7 +9,7 @@ let pkgs = nixpkgs.legacyPackages.${system}; drv = with pkgs; pkgs.mkShell { name = "shell"; - buildInputs = [nodejs_20 pkg-config cairo pango libpng libjpeg giflib gcc libuuid.out yarn docker-compose]; + buildInputs = [nodejs_20 pkg-config cairo pango libpng libjpeg giflib gcc libuuid.out yarn docker-compose mongosh]; shellHook = '' export LD_LIBRARY_PATH=${libuuid.out}/lib:$LD_LIBRARY_PATH ''; diff --git a/server/routes/cube/export.js b/server/routes/cube/export.js index b22a4e59b..569ecd9fa 100644 --- a/server/routes/cube/export.js +++ b/server/routes/cube/export.js @@ -1,7 +1,7 @@ import { sortForDownload } from '@cubeartisan/client/utils/Sort.js'; import { makeFilter } from '@cubeartisan/client/filtering/FilterCards.js'; import carddb from '@cubeartisan/server/serverjs/cards.js'; -import { handleRouteError } from '@cubeartisan/server/routes/middleware.js'; +import { handleRouteError, setCorsUnrestricted } from '@cubeartisan/server/routes/middleware.js'; import { buildIdQuery } from '@cubeartisan/server/serverjs/cubefn.js'; import { writeCard, CSV_HEADER, exportToMtgo } from '@cubeartisan/server/routes/cube/helper.js'; import Cube from '@cubeartisan/server/models/cube.js'; @@ -28,7 +28,7 @@ export const sortCardsByQuery = (req, cards) => { ); }; -export const exportCubeToJson = async (req, res) => { +const exportCubeToJsonHandler = async (req, res) => { try { const cube = await Cube.findOne(buildIdQuery(req.params.id)).lean(); @@ -42,8 +42,9 @@ export const exportCubeToJson = async (req, res) => { return handleRouteError(req, res, err, `/cube/${req.params.id}/list`); } }; +export const exportCubeToJson = [setCorsUnrestricted, exportCubeToJsonHandler]; -export const exportCubeToCubeCobra = async (req, res) => { +const exportCubeToCubeCobraHandler = async (req, res) => { try { const cube = await Cube.findOne(buildIdQuery(req.params.id)).lean(); if (!cube) { @@ -69,8 +70,9 @@ export const exportCubeToCubeCobra = async (req, res) => { return handleRouteError(req, res, err, `/cube/${req.params.id}/list`); } }; +export const exportCubeToCubeCobra = [setCorsUnrestricted, exportCubeToCubeCobraHandler]; -export const exportCubeToCsv = async (req, res) => { +const exportCubeToCsvHandler = async (req, res) => { try { const cube = await Cube.findOne(buildIdQuery(req.params.id)).lean(); @@ -104,8 +106,9 @@ export const exportCubeToCsv = async (req, res) => { return handleRouteError(req, res, err, `/cube/${req.params.id}/list`); } }; +export const exportCubeToCsv = [setCorsUnrestricted, exportCubeToCsvHandler]; -export const exportCubeToForge = async (req, res) => { +const exportCubeToForgeHandler = async (req, res) => { try { const cube = await Cube.findOne(buildIdQuery(req.params.id)).lean(); if (!cube) { @@ -134,8 +137,9 @@ export const exportCubeToForge = async (req, res) => { return handleRouteError(req, res, err, `/cube/${req.params.id}/list`); } }; +export const exportCubeToForge = [setCorsUnrestricted, exportCubeToForgeHandler]; -export const exportCubeToMtgo = async (req, res) => { +const exportCubeToMtgoHandler = async (req, res) => { try { const cube = await Cube.findOne(buildIdQuery(req.params.id)).lean(); if (!cube) { @@ -155,8 +159,9 @@ export const exportCubeToMtgo = async (req, res) => { return handleRouteError(req, res, err, `/cube/${req.params.id}/list`); } }; +export const exportCubeToMtgo = [setCorsUnrestricted, exportCubeToMtgoHandler]; -export const exportCubeToXmage = async (req, res) => { +const exportCubeToXmageHandler = async (req, res) => { try { const cube = await Cube.findOne(buildIdQuery(req.params.id)).lean(); if (!cube) { @@ -182,8 +187,9 @@ export const exportCubeToXmage = async (req, res) => { return handleRouteError(req, res, err, `/cube/${req.params.id}/list`); } }; +export const exportCubeToXmage = [setCorsUnrestricted, exportCubeToXmageHandler]; -export const exportCubeToPlaintext = async (req, res) => { +const exportCubeToPlaintextHandler = async (req, res) => { try { const cube = await Cube.findOne(buildIdQuery(req.params.id)).lean(); if (!cube) { @@ -209,8 +215,9 @@ export const exportCubeToPlaintext = async (req, res) => { return handleRouteError(req, res, err, `/cube/${req.params.id}/list`); } }; +export const exportCubeToPlaintext = [setCorsUnrestricted, exportCubeToPlaintextHandler]; -export const exportCubeToPlaintextLower = async (req, res) => { +const exportCubeToPlaintextLowerHandler = async (req, res) => { try { const cube = await Cube.findOne(buildIdQuery(req.params.id)).lean(); if (!cube) { @@ -237,3 +244,4 @@ export const exportCubeToPlaintextLower = async (req, res) => { return handleRouteError(req, res, err, `/cube/${req.params.id}/list`); } }; +export const exportCubeToPlaintextLower = [setCorsUnrestricted, exportCubeToPlaintextLowerHandler];