Skip to content

Commit

Permalink
feat(cors): Disable cors on the export routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruler501 committed Jan 5, 2024
1 parent d556061 commit 5d79e66
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .docker/Dockerfile.jobs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
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"
cubeartisan:
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:
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'';
Expand Down
26 changes: 17 additions & 9 deletions server/routes/cube/export.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand All @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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];

0 comments on commit 5d79e66

Please sign in to comment.