diff --git a/README.md b/README.md index 402b720d..fa951b5c 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ http://it2810-03.idi.ntnu.no/project2/ | Part | Technology | | -------- | --------------------------------------------------------------------------------- | | Frontend | React, TypeScript, Vite, Apollo Client, React Router, i18next | -| Backend | Node.js, TypeScript, Apollo Server (GraphQL) | +| Backend | Node.js, TypeScript, Express, Apollo Server (GraphQL) | | Database | MongoDB, running on the course VM | | Testing | Vitest, React Testing Library, jsdom, mongodb-memory-server, Playwright, axe-core | | Tooling | ESLint, Prettier, GitHub Actions | @@ -93,7 +93,7 @@ From the repo root: npm run dev ``` -This starts both the backend (http://localhost:3001) and the frontend. Open http://localhost:5173/project2/ in your browser. The frontend forwards `/graphql` requests to the backend, so both must be running. +This starts both the backend (http://localhost:3001) and the frontend. Open http://localhost:5173/project2/ in your browser. The frontend forwards `/graphql` and `/images` (the plant images) to the backend, so both must be running. ## Deployment on the VM @@ -101,7 +101,7 @@ The deployed app runs on the VM `it2810-03.idi.ntnu.no`. Apache serves the front ```text Browser ──> Apache (port 80, /project2) serves the built frontend - ──> Backend (port 3001, /graphql) run by pm2, Node.js + ──> Backend (port 3001, /graphql, /images) run by pm2, Node.js └──> MongoDB (127.0.0.1:27017) only reachable from the VM ``` @@ -148,5 +148,5 @@ See [quality.md](docs/quality.md) for work practices, accessibility, sustainable ## Known issues -- The plant images are stored as base64 in the database and sent inside the GraphQL responses. This makes the responses larger, and the browser can't cache the images or load them lazily. See [Limitations of the architecture](docs/architecture.md#limitations-of-the-architecture) for why we chose it and how it could be improved in further development. +- The plant images are stored as base64 in the database, which takes about 33 % more space than image files. See [Limitations of the architecture](docs/architecture.md#limitations-of-the-architecture) for why we chose it and how it could be improved. - The plant descriptions and names on the plant cards are not translated to Norwegian, since they come from the English Perenual API. The watering, sunlight and care values are translated. diff --git a/backend/package-lock.json b/backend/package-lock.json index af07cd56..45624420 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -9,12 +9,17 @@ "version": "1.0.0", "dependencies": { "@apollo/server": "^5.5.1", + "@as-integrations/express5": "^1.1.2", + "cors": "^2.8.6", "dotenv": "^18.0.5", + "express": "^5.3.0", "graphql": "^16.14.2", "mongodb": "^7.7.0" }, "devDependencies": { "@eslint/js": "^10.0.1", + "@types/cors": "^2.8.19", + "@types/express": "^5.0.6", "@types/node": "^26.6.3", "@vitest/coverage-v8": "^5.0.5", "eslint": "^10.12.0", @@ -269,6 +274,19 @@ "node": ">=16" } }, + "node_modules/@as-integrations/express5": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@as-integrations/express5/-/express5-1.1.2.tgz", + "integrity": "sha512-BxfwtcWNf2CELDkuPQxi5Zl3WqY/dQVJYafeCBOGoFQjv5M0fjhxmAFZ9vKx/5YKKNeok4UY6PkFbHzmQrdxIA==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "@apollo/server": "^4.0.0 || ^5.0.0", + "express": "^5.0.0" + } + }, "node_modules/@babel/helper-string-parser": { "version": "7.29.15", "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.15.tgz", @@ -353,43 +371,6 @@ "keyv": "^5.6.0" } }, - "node_modules/@emnapi/core": { - "version": "2.0.0-beta.2", - "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.2.tgz", - "integrity": "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "@emnapi/wasi-threads": "2.2.0", - "tslib": "^2.4.0" - } - }, - "node_modules/@emnapi/runtime": { - "version": "2.0.0-beta.2", - "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.2.tgz", - "integrity": "sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, - "node_modules/@emnapi/wasi-threads": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz", - "integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, "node_modules/@esbuild/aix-ppc64": { "version": "0.28.2", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz", @@ -1154,29 +1135,6 @@ "sparse-bitfield": "^3.0.3" } }, - "node_modules/@napi-rs/wasm-runtime": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.6.tgz", - "integrity": "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "@tybys/wasm-util": "^0.10.3" - }, - "engines": { - "node": "^20.19.0 || ^22.13.0 || >=23.5.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - }, - "peerDependencies": { - "@emnapi/core": "^1.7.1 || 2.0.0-beta.2", - "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2" - } - }, "node_modules/@oxc-project/types": { "version": "0.156.0", "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.156.0.tgz", @@ -1251,369 +1209,165 @@ "integrity": "sha512-b1UQwcEZ4yCnMCD8DAL1VlbvBJE9/IX4FTIp7BG1xYpf29SLazLSrqUkj4w7Y5y7cCVP6E5tcqqcI0xemPkHug==", "license": "BSD-3-Clause" }, - "node_modules/@rolldown/binding-android-arm-eabi": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.19.tgz", - "integrity": "sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==", - "cpu": [ - "arm" - ], + "node_modules/@rolldown/pluginutils": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.1.tgz", + "integrity": "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" - } + "peer": true }, - "node_modules/@rolldown/binding-android-arm64": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.19.tgz", - "integrity": "sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==", - "cpu": [ - "arm64" - ], + "node_modules/@types/body-parser": { + "version": "1.19.6", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz", + "integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" + "dependencies": { + "@types/connect": "*", + "@types/node": "*" } }, - "node_modules/@rolldown/binding-darwin-arm64": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.19.tgz", - "integrity": "sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==", - "cpu": [ - "arm64" - ], + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" } }, - "node_modules/@rolldown/binding-darwin-x64": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.19.tgz", - "integrity": "sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==", - "cpu": [ - "x64" - ], + "node_modules/@types/connect": { + "version": "3.4.38", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", + "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" + "dependencies": { + "@types/node": "*" } }, - "node_modules/@rolldown/binding-freebsd-x64": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.19.tgz", - "integrity": "sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==", - "cpu": [ - "x64" - ], + "node_modules/@types/cors": { + "version": "2.8.19", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz", + "integrity": "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" + "dependencies": { + "@types/node": "*" } }, - "node_modules/@rolldown/binding-linux-arm-gnueabihf": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.19.tgz", - "integrity": "sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==", - "cpu": [ - "arm" - ], + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" - } + "license": "MIT" }, - "node_modules/@rolldown/binding-linux-arm64-gnu": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.19.tgz", - "integrity": "sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==", - "cpu": [ - "arm64" - ], + "node_modules/@types/esrecurse": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", + "integrity": "sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==", "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" - } + "license": "MIT" }, - "node_modules/@rolldown/binding-linux-arm64-musl": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.19.tgz", - "integrity": "sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==", - "cpu": [ - "arm64" - ], + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" - } + "license": "MIT" }, - "node_modules/@rolldown/binding-linux-ppc64-gnu": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.19.tgz", - "integrity": "sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==", - "cpu": [ - "ppc64" - ], + "node_modules/@types/express": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.6.tgz", + "integrity": "sha512-sKYVuV7Sv9fbPIt/442koC7+IIwK5olP1KWeD88e/idgoJqDm3JV/YUiPwkoKK92ylff2MGxSz1CSjsXelx0YA==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^5.0.0", + "@types/serve-static": "^2" } }, - "node_modules/@rolldown/binding-linux-s390x-gnu": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.19.tgz", - "integrity": "sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==", - "cpu": [ - "s390x" - ], + "node_modules/@types/express-serve-static-core": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.1.3.tgz", + "integrity": "sha512-dPfW8NFiOF4wOHc7+N/QSxlY9cfSsenewGbAz8C8U/MULPd/YZ27LvJUIlzaXie7e6Ove9YunJGgC9tbHD2cKw==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*", + "@types/send": "*" } }, - "node_modules/@rolldown/binding-linux-x64-gnu": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.19.tgz", - "integrity": "sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==", - "cpu": [ - "x64" - ], + "node_modules/@types/http-errors": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz", + "integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/long": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz", + "integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==", + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "26.6.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.6.tgz", + "integrity": "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" + "dependencies": { + "undici-types": "~8.9.0" } }, - "node_modules/@rolldown/binding-linux-x64-musl": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.19.tgz", - "integrity": "sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==", - "cpu": [ - "x64" - ], + "node_modules/@types/qs": { + "version": "6.15.1", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.1.tgz", + "integrity": "sha512-GZHUBZR9hckSUhrxmp1nG6NwdpM9fCunJwyThLW1X3AyHgd9IlHb6VANpQQqDr2o/qQp6McZ3y/IA2rVzKzSbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/range-parser": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", + "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz", + "integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" + "dependencies": { + "@types/node": "*" } }, - "node_modules/@rolldown/binding-openharmony-arm64": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.19.tgz", - "integrity": "sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openharmony" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" - } - }, - "node_modules/@rolldown/binding-wasm32-wasi": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.2.19.tgz", - "integrity": "sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==", - "cpu": [ - "wasm32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "@emnapi/core": "2.0.0-beta.2", - "@emnapi/runtime": "2.0.0-beta.2", - "@napi-rs/wasm-runtime": "1.2.6" - }, - "engines": { - "node": "^20.19.0 || ^22.13.0 || >=23.5.0" - } - }, - "node_modules/@rolldown/binding-win32-arm64-msvc": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.19.tgz", - "integrity": "sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" - } - }, - "node_modules/@rolldown/binding-win32-x64-msvc": { - "version": "1.2.19", - "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.19.tgz", - "integrity": "sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "peer": true, - "engines": { - "node": "^20.19.0 || >=22.12.0" - } - }, - "node_modules/@rolldown/pluginutils": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.1.tgz", - "integrity": "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==", - "dev": true, - "license": "MIT", - "peer": true - }, - "node_modules/@tybys/wasm-util": { - "version": "0.10.5", - "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.5.tgz", - "integrity": "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, - "node_modules/@types/chai": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", - "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/deep-eql": "*", - "assertion-error": "^2.0.1" - } - }, - "node_modules/@types/deep-eql": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", - "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/esrecurse": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", - "integrity": "sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/estree": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", - "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/json-schema": { - "version": "7.0.15", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", - "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/long": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz", - "integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==", - "license": "MIT" - }, - "node_modules/@types/node": { - "version": "26.6.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.6.tgz", - "integrity": "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==", + "node_modules/@types/serve-static": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-2.2.0.tgz", + "integrity": "sha512-8mam4H1NHLtu7nmtalF7eyBH14QyOASmcxHhSfEoRyr0nP/YdoesEtU+uSRvMe96TW/HPTtkoKqQLl53N7UXMQ==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~8.9.0" + "@types/http-errors": "*", + "@types/node": "*" } }, "node_modules/@types/webidl-conversions": { @@ -1969,6 +1723,19 @@ "node": ">=16.0.0" } }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/acorn": { "version": "8.19.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.19.0.tgz", @@ -2355,6 +2122,19 @@ "dev": true, "license": "MIT" }, + "node_modules/content-disposition": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-2.0.1.tgz", + "integrity": "sha512-e+H0ZXHSWYrENhQzw1LPuP4oF5MzVKmDU6d3hxlvaPEYLLg62MxtQNPRx4SYSuYJSBUgnQIG4HIN2tEtNv7Dog==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/content-type": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", @@ -2364,6 +2144,24 @@ "node": ">= 0.6" } }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, "node_modules/cors": { "version": "2.8.6", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", @@ -2796,6 +2594,15 @@ "node": ">=0.10.0" } }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/events-universal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/events-universal/-/events-universal-1.0.1.tgz", @@ -2816,6 +2623,62 @@ "node": ">=12.0.0" } }, + "node_modules/express": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/express/-/express-5.3.0.tgz", + "integrity": "sha512-qCqy1xSoaugxOD4IVHb1ZWdkvCF2W3aE2okKouWj8VwJ+ztskSiXoBnCSJqfKT+cVPJhuJqe9YLbY425+Zh00g==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.3.0", + "content-disposition": "^2.0.1", + "content-type": "^2.0.0", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.8", + "qs": "^6.16.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.1.0", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2983,6 +2846,24 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -3238,385 +3119,158 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "license": "ISC" }, - "node_modules/is-callable": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", - "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", "license": "MIT", "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-glob": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", - "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, - "license": "MIT", - "dependencies": { - "is-extglob": "^2.1.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-typed-array": { - "version": "1.1.15", - "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.15.tgz", - "integrity": "sha512-p3EcsicXjit7SaskXHs1hA91QxgTw46Fv6EFKKGS5DRFLD8yKnohjF3hxoju94b/OcMZoQukzpPpBE9uLVKzgQ==", - "license": "MIT", - "dependencies": { - "which-typed-array": "^1.1.16" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/isarray": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", - "license": "MIT" - }, - "node_modules/isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true, - "license": "ISC" - }, - "node_modules/js-tokens": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.1.tgz", - "integrity": "sha512-XMt+uh+yEs6srFvEb/pEe4IMvbtoXVdNxF7lZFU+I9sdWI641L97L+gXQMTGm1x3RjPUVizNVjHueclXr0U7sw==", - "dev": true, - "license": "MIT" - }, - "node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true, - "license": "MIT" - }, - "node_modules/json-stable-stringify-without-jsonify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", - "dev": true, - "license": "MIT" - }, - "node_modules/keyv": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-5.6.0.tgz", - "integrity": "sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@keyv/serialize": "^1.1.1" - } - }, - "node_modules/levn": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", - "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "prelude-ls": "^1.2.1", - "type-check": "~0.4.0" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/lightningcss": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", - "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", - "dev": true, - "license": "MPL-2.0", - "peer": true, - "dependencies": { - "detect-libc": "^2.0.3" - }, - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - }, - "optionalDependencies": { - "lightningcss-android-arm64": "1.33.0", - "lightningcss-darwin-arm64": "1.33.0", - "lightningcss-darwin-x64": "1.33.0", - "lightningcss-freebsd-x64": "1.33.0", - "lightningcss-linux-arm-gnueabihf": "1.33.0", - "lightningcss-linux-arm64-gnu": "1.33.0", - "lightningcss-linux-arm64-musl": "1.33.0", - "lightningcss-linux-x64-gnu": "1.33.0", - "lightningcss-linux-x64-musl": "1.33.0", - "lightningcss-win32-arm64-msvc": "1.33.0", - "lightningcss-win32-x64-msvc": "1.33.0" - } - }, - "node_modules/lightningcss-android-arm64": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", - "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "android" - ], - "peer": true, - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-darwin-arm64": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", - "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-darwin-x64": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", - "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-freebsd-x64": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", - "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "freebsd" - ], - "peer": true, - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-linux-arm-gnueabihf": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", - "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-linux-arm64-gnu": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", - "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-linux-arm64-musl": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", - "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], - "peer": true, + "node": ">= 0.10" + } + }, + "node_modules/is-callable": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "license": "MIT", "engines": { - "node": ">= 12.0.0" + "node": ">= 0.4" }, "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/lightningcss-linux-x64-gnu": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", - "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", - "cpu": [ - "x64" - ], + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], - "peer": true, + "license": "MIT", "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "node": ">=0.10.0" } }, - "node_modules/lightningcss-linux-x64-musl": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", - "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", - "cpu": [ - "x64" - ], + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], - "peer": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, "engines": { - "node": ">= 12.0.0" + "node": ">=0.10.0" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/is-typed-array": { + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.15.tgz", + "integrity": "sha512-p3EcsicXjit7SaskXHs1hA91QxgTw46Fv6EFKKGS5DRFLD8yKnohjF3hxoju94b/OcMZoQukzpPpBE9uLVKzgQ==", + "license": "MIT", + "dependencies": { + "which-typed-array": "^1.1.16" + }, + "engines": { + "node": ">= 0.4" }, "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/lightningcss-win32-arm64-msvc": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", - "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", - "cpu": [ - "arm64" - ], + "node_modules/isarray": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "license": "MIT" + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "win32" - ], - "peer": true, - "engines": { - "node": ">= 12.0.0" + "license": "ISC" + }, + "node_modules/js-tokens": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.1.tgz", + "integrity": "sha512-XMt+uh+yEs6srFvEb/pEe4IMvbtoXVdNxF7lZFU+I9sdWI641L97L+gXQMTGm1x3RjPUVizNVjHueclXr0U7sw==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true, + "license": "MIT" + }, + "node_modules/keyv": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-5.6.0.tgz", + "integrity": "sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@keyv/serialize": "^1.1.1" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "engines": { + "node": ">= 0.8.0" } }, - "node_modules/lightningcss-win32-x64-msvc": { + "node_modules/lightningcss": { "version": "1.33.0", - "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", - "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", - "cpu": [ - "x64" - ], + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", "dev": true, "license": "MPL-2.0", - "optional": true, - "os": [ - "win32" - ], "peer": true, + "dependencies": { + "detect-libc": "^2.0.3" + }, "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" } }, "node_modules/locate-path": { @@ -3745,6 +3399,18 @@ "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", "license": "MIT" }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/mime-db": { "version": "1.54.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", @@ -4058,6 +3724,15 @@ "url": "https://opencollective.com/express" } }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -4147,6 +3822,16 @@ "node": ">=8" } }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -4293,6 +3978,23 @@ "node": ">= 0.8.0" } }, + "node_modules/proxy-addr": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", + "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -4338,6 +4040,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/range-parser": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz", + "integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/raw-body": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", @@ -4398,6 +4113,26 @@ "@rolldown/binding-win32-x64-msvc": "1.2.19" } }, + "node_modules/router": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.3.0.tgz", + "integrity": "sha512-bpowRfGjEPe8t9R6fJIzhwmyCGAXwKvxBUsgJm+bJukwdcWmUXbMo7p22w7aYmQBPQTUMNqMV39YX0kMou3z8w==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -4437,6 +4172,51 @@ "node": ">=10" } }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/set-function-length": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", @@ -5159,6 +4939,12 @@ "node": ">=0.10.0" } }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, "node_modules/yauzl": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-3.4.0.tgz", diff --git a/backend/package.json b/backend/package.json index bf38285e..0b370516 100644 --- a/backend/package.json +++ b/backend/package.json @@ -19,12 +19,17 @@ }, "dependencies": { "@apollo/server": "^5.5.1", + "@as-integrations/express5": "^1.1.2", + "cors": "^2.8.6", "dotenv": "^18.0.5", + "express": "^5.3.0", "graphql": "^16.14.2", "mongodb": "^7.7.0" }, "devDependencies": { "@eslint/js": "^10.0.1", + "@types/cors": "^2.8.19", + "@types/express": "^5.0.6", "@types/node": "^26.6.3", "@vitest/coverage-v8": "^5.0.5", "eslint": "^10.12.0", diff --git a/backend/src/app.ts b/backend/src/app.ts new file mode 100644 index 00000000..e485f637 --- /dev/null +++ b/backend/src/app.ts @@ -0,0 +1,25 @@ +import express from "express"; +import cors from "cors"; +import { ApolloServer } from "@apollo/server"; +import { expressMiddleware } from "@as-integrations/express5"; +import { resolvers } from "./resolvers/index.js"; +import { typeDefs } from "./schema.js"; +import { sendPlantImage } from "./images.js"; + +// The backend app: the GraphQL API on /graphql and the plant images on +// /images/:id. Express is used instead of Apollo's standalone server, since +// that one can only serve GraphQL and not the images next to it. +// Returns the Apollo server too, so the tests can send it GraphQL requests +// without opening a port. +export async function createApp() { + const apollo = new ApolloServer({ typeDefs, resolvers }); + await apollo.start(); + + const app = express(); + // The frontend is served by Apache on another port, so it needs CORS + app.use(cors()); + app.get("/images/:id", sendPlantImage); + app.use("/graphql", express.json(), expressMiddleware(apollo)); + + return { app, apollo }; +} diff --git a/backend/src/images.ts b/backend/src/images.ts new file mode 100644 index 00000000..cbb92683 --- /dev/null +++ b/backend/src/images.ts @@ -0,0 +1,42 @@ +import type { Request, Response } from "express"; +import { ObjectId } from "mongodb"; +import { db } from "./db.js"; +import type { PlantDoc } from "./types.js"; + +// The plant images are stored in MongoDB as base64 data URIs (see +// seedDataFetch.js). This route sends one of them as a normal image file, so +// the GraphQL responses only contain a link to it. The browser can then load +// the images separately, lazily and from its cache, and they are sent as +// bytes instead of base64 text, which is about 33 % smaller. + +// How long the browser may reuse an image without asking the server again. +// A plant's image never changes while the app runs, so a week is safe. +const CACHE_SECONDS = 7 * 24 * 60 * 60; + +// "data:image/jpeg;base64,/9j/4AAQ..." gives the type and the base64 data +const DATA_URI = /^data:([\w/+.-]+);base64,(.*)$/s; + +// The path the frontend gets in imageURL for a plant with a stored image +export const imagePath = (plantId: string) => `/images/${plantId}`; + +// GET /images/:id. Answers 404 for a malformed id, an unknown plant or a +// plant without a stored image. +export async function sendPlantImage( + req: Request<{ id: string }>, + res: Response, +): Promise { + const { id } = req.params; + const doc = ObjectId.isValid(id) + ? await db + .collection("plants") + .findOne({ _id: new ObjectId(id) }, { projection: { imageData: 1 } }) + : null; + const match = doc?.imageData?.match(DATA_URI); + if (!match) { + res.sendStatus(404); + return; + } + + res.set("Cache-Control", `public, max-age=${CACHE_SECONDS}`); + res.type(match[1]).send(Buffer.from(match[2], "base64")); +} diff --git a/backend/src/listen.ts b/backend/src/listen.ts new file mode 100644 index 00000000..ed11f815 --- /dev/null +++ b/backend/src/listen.ts @@ -0,0 +1,13 @@ +import { createServer } from "node:http"; +import type { Express } from "express"; + +// Starts listening on the port. Rejects if it fails, e.g. when the port is +// already in use, so the server stops with the error instead of hanging. +// In its own file, so the tests can replace it and not open a port. +export function listen(app: Express, port: number): Promise { + return new Promise((resolve, reject) => { + const server = createServer(app); + server.once("error", reject); + server.listen(port, () => resolve()); + }); +} diff --git a/backend/src/resolvers/plants.ts b/backend/src/resolvers/plants.ts index 3b745731..b6f27467 100644 --- a/backend/src/resolvers/plants.ts +++ b/backend/src/resolvers/plants.ts @@ -17,6 +17,7 @@ import type { PlantPage, } from "../types.js"; import { DEFAULT_PAGE_SIZE, MAX_LIMIT } from "../schema.js"; +import { imagePath } from "../images.js"; import { plants, toObjectId } from "./helpers.js"; // Keeps limit between 1 and MAX_LIMIT, and offset at 0 or more, so a bad value @@ -30,7 +31,12 @@ const clampOffset = (offset: number | null | undefined) => const toPlant = (doc: WithId): Plant => ({ id: doc._id.toString(), name: doc.commonName.replace(/\*/g, "").replace(/\s+/g, " ").trim(), - imageURL: doc.imageData ?? doc.imageURL ?? null, + // A link to the stored image, which /images/:id sends as a file. The old + // Perenual URL is only used if no image was stored. + imageURL: + doc.hasImage || doc.imageData + ? imagePath(doc._id.toString()) + : (doc.imageURL ?? null), scientificName: doc.scientificName, description: doc.description, watering: doc.watering, @@ -38,6 +44,15 @@ const toPlant = (doc: WithId): Plant => ({ careLevel: doc.careLevel, }); +// The image itself is not read from the database when plants are listed, +// only whether there is one. The frontend gets a link to it, and the image is +// sent by /images/:id. Strings are greater than null in MongoDB, so a missing +// or null imageData gives false. +const withoutImageData: Document[] = [ + { $addFields: { hasImage: { $gt: ["$imageData", null] } } }, + { $project: { imageData: 0 } }, +]; + // One page of plants for Explore Plants and My Matches: the plants matching the // base filter (on My Matches the user's matches) and the user's search and // filters, the total count, and the match counts for the filter values, so the @@ -57,6 +72,7 @@ export const findPlantPage = async ( ...sortStages, { $skip: clampOffset(args.offset) }, { $limit: clampLimit(args.limit, DEFAULT_PAGE_SIZE) }, + ...withoutImageData, ]) .toArray(), plants.countDocuments(filter), @@ -113,7 +129,8 @@ export const plantQueries = { { $project: { commonName: 1, - imageData: 1, + // Only whether there is an image, see withoutImageData + hasImage: { $gt: ["$imageData", null] }, imageURL: 1, scientificName: 1, description: 1, diff --git a/backend/src/server.ts b/backend/src/server.ts index 8d66699e..aa3c7fef 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -1,9 +1,7 @@ -import { ApolloServer } from "@apollo/server"; -import { startStandaloneServer } from "@apollo/server/standalone"; -import { resolvers } from "./resolvers/index.js"; -import { typeDefs } from "./schema.js"; import { db } from "./db.js"; import { ensureIndexes } from "./indexes.js"; +import { createApp } from "./app.js"; +import { listen } from "./listen.js"; import { migrateData } from "./migrations.js"; // Create the database indexes and update old data before the server starts @@ -11,10 +9,8 @@ import { migrateData } from "./migrations.js"; await ensureIndexes(db); await migrateData(db); -const server = new ApolloServer({ typeDefs, resolvers }); +const { app } = await createApp(); +const port = Number(process.env.PORT) || 3001; +await listen(app, port); -const { url } = await startStandaloneServer(server, { - listen: { port: Number(process.env.PORT) || 3001 }, -}); - -console.log(`Server running at: ${url}`); +console.log(`Server running at: http://localhost:${port}/graphql`); diff --git a/backend/src/types.ts b/backend/src/types.ts index b81a5c47..a3924a94 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -5,6 +5,8 @@ export interface PlantDoc { commonName: string; // Base64-encoded Perenual image as a data URI, stored by seedDataFetch.js imageData?: string | null; + // Set by the queries instead of imageData, which is only sent by /images/:id + hasImage?: boolean; imageURL?: string | null; scientificName?: string[]; description?: string; diff --git a/backend/tests/server.test.ts b/backend/tests/server.test.ts index ed5d0704..7b146978 100644 --- a/backend/tests/server.test.ts +++ b/backend/tests/server.test.ts @@ -1,4 +1,6 @@ import type { ApolloServer } from "@apollo/server"; +import type { Express } from "express"; +import { createServer, type Server } from "node:http"; import { Collection, ObjectId, type Db, type MongoClient } from "mongodb"; import { afterAll, @@ -20,44 +22,43 @@ vi.mock("../src/db.js", async () => { return { client, db: client.db("server-test") }; }); -// Instead of opening a port, remember the server so the tests can send it requests -const { startStandaloneServer } = vi.hoisted(() => ({ - startStandaloneServer: vi.fn(), -})); -vi.mock("@apollo/server/standalone", () => ({ startStandaloneServer })); - -type StartOptions = { listen: { port: number } }; +// Instead of opening a port, the tests get the app from createApp, and +// listen is replaced, so the tests for starting the server only check the port +const { listen } = vi.hoisted(() => ({ listen: vi.fn() })); +vi.mock("../src/listen.js", () => ({ listen })); // server.ts starts as soon as it is imported, so each call imports a fresh copy. -// Returns the server it started, the options it started with, and the database. +// Returns the port it listened on. async function importServer() { vi.resetModules(); - startStandaloneServer.mockClear(); + listen.mockClear(); try { await import("../src/server.js"); } finally { const { client } = await import("../src/db.js"); clients.push(client); } - const [server, options] = startStandaloneServer.mock.calls[0] as [ - ApolloServer, - StartOptions, - ]; - const { db } = await import("../src/db.js"); - return { server, options, db }; + const [, port] = listen.mock.calls[0] as [Express, number]; + return { port }; } const clients: MongoClient[] = []; +let app: Express; let server: ApolloServer; let db: Db; beforeAll(async () => { vi.spyOn(console, "log").mockImplementation(() => {}); - startStandaloneServer.mockResolvedValue({ url: "http://localhost:3001/" }); - ({ server, db } = await importServer()); + listen.mockResolvedValue(undefined); + const { createApp } = await import("../src/app.js"); + ({ app, apollo: server } = await createApp()); + const dbModule = await import("../src/db.js"); + db = dbModule.db; + clients.push(dbModule.client); }); afterAll(async () => { + await server.stop(); await db.dropDatabase(); await Promise.all(clients.map((client) => client.close())); }); @@ -168,24 +169,24 @@ describe("starting the server", () => { it("listens on port 3001 and logs the address", async () => { vi.stubEnv("PORT", undefined); - const { options } = await importServer(); + const { port } = await importServer(); - expect(options.listen.port).toBe(3001); + expect(port).toBe(3001); expect(console.log).toHaveBeenCalledWith( - "Server running at: http://localhost:3001/", + "Server running at: http://localhost:3001/graphql", ); }); it("listens on the port in PORT", async () => { vi.stubEnv("PORT", "4000"); - const { options } = await importServer(); + const { port } = await importServer(); - expect(options.listen.port).toBe(4000); + expect(port).toBe(4000); }); it("stops with the error when the port is already in use", async () => { - startStandaloneServer.mockRejectedValueOnce( + listen.mockRejectedValueOnce( new Error("listen EADDRINUSE: address already in use :::3001"), ); @@ -193,6 +194,73 @@ describe("starting the server", () => { }); }); +// The plant images are sent as files by /images/:id. These tests start the app +// on a free port and fetch the images like the browser does. +describe("plant images", () => { + let http: Server; + let baseUrl: string; + + beforeAll(async () => { + http = createServer(app); + await new Promise((resolve) => http.listen(0, resolve)); + const address = http.address(); + if (typeof address !== "object" || !address) throw new Error("No port"); + baseUrl = `http://localhost:${address.port}`; + }); + + afterAll(async () => { + await new Promise((resolve) => http.close(resolve)); + }); + + // A tiny PNG, 1 × 1 pixel + const PNG_BASE64 = + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="; + + async function insertPlant(fields: Record) { + const { insertedId } = await db + .collection("plants") + .insertOne({ commonName: "Plant", ...fields }); + return insertedId.toString(); + } + + it("sends the stored image as a file that the browser may cache", async () => { + const id = await insertPlant({ + imageData: `data:image/png;base64,${PNG_BASE64}`, + }); + + const response = await fetch(`${baseUrl}/images/${id}`); + + expect(response.status).toBe(200); + expect(response.headers.get("content-type")).toBe("image/png"); + expect(response.headers.get("cache-control")).toBe( + "public, max-age=604800", + ); + // The bytes of the image, not the base64 text + const body = Buffer.from(await response.arrayBuffer()); + expect(body.equals(Buffer.from(PNG_BASE64, "base64"))).toBe(true); + }); + + it.each([ + ["a plant without a stored image", async () => insertPlant({})], + ["a plant that does not exist", async () => new ObjectId().toString()], + ["a malformed id", async () => "not-an-id"], + ])("answers 404 for %s", async (_, makeId) => { + const response = await fetch(`${baseUrl}/images/${await makeId()}`); + + expect(response.status).toBe(404); + }); + + it("serves GraphQL on /graphql", async () => { + const response = await fetch(`${baseUrl}/graphql`, { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ query: "{ __typename }" }), + }); + + expect(await response.json()).toEqual({ data: { __typename: "Query" } }); + }); +}); + describe("plants", () => { // Made-up plants with the same spellings as the real data, e.g. both "Medium" and "Moderate" const PLANTS = [ @@ -334,9 +402,9 @@ describe("plants", () => { } }); - it("uses the stored image data before the image URL", async () => { + it("links to the stored image instead of sending it, before the image URL", async () => { await db.collection("plants").deleteMany({}); - await insertPlants( + const [both] = await insertPlants( { commonName: "Both", imageData: "data:image/png;base64,AAA", @@ -346,19 +414,27 @@ describe("plants", () => { { commonName: "No image" }, ); - const result = await execute<{ - getPlants: { name: string; imageURL: string | null }[]; - }>("query { getPlants { name imageURL } }"); - - expect( - Object.fromEntries( - result.data!.getPlants.map((p) => [p.name, p.imageURL]), - ), - ).toEqual({ - Both: "data:image/png;base64,AAA", - "Only URL": "b.png", - "No image": null, - }); + for (const query of [ + "query { getPlants { name imageURL } }", + "query { explorePlants { plants { name imageURL } } }", + ]) { + const result = await execute>(query); + const list = (result.data!.getPlants ?? + (result.data!.explorePlants as { plants: unknown }).plants) as { + name: string; + imageURL: string | null; + }[]; + + expect(Object.fromEntries(list.map((p) => [p.name, p.imageURL]))).toEqual( + { + Both: `/images/${both}`, + "Only URL": "b.png", + "No image": null, + }, + ); + // The base64 image is never in the GraphQL response + expect(JSON.stringify(result)).not.toContain("base64"); + } }); it("explorePlants sorts by name and counts all plants by default", async () => { diff --git a/docs/architecture.md b/docs/architecture.md index 351608f1..483e6c56 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -15,9 +15,10 @@ Perenual API → seedDataFetch.js ─┐ ▲ │ MongoDB driver (db.ts) │ - Apollo Server, GraphQL (server.ts, port 3001) + Express + Apollo Server (server.ts, port 3001) ▲ - │ GraphQL over HTTP (/graphql) + │ GraphQL over HTTP (/graphql), + │ plant images as files (/images/:id) │ Frontend: React + Apollo Client (localStorage: userId, theme, language, walkthroughSeen, @@ -110,7 +111,7 @@ All user queries and mutations ask for the same `UserFields` fragment, so when o The backend exposes a single GraphQL endpoint. With GraphQL, the frontend asks for exactly the fields each view needs. A plant card needs more fields than a list item, and both are served by the same `Plant` type without extra endpoints. The schema also gives us one typed contract between frontend and backend. - `db.ts` connects to MongoDB using `MONGODB_URI` and `DB_NAME` from `.env` (see `.env.example`). The database name defaults to `iloveplants`. -- `server.ts` starts Apollo Server on `PORT` (default 3001) with the schema and resolvers below. +- `server.ts` starts the backend on `PORT` (default 3001). `app.ts` sets up Express with the GraphQL API (Apollo Server, with the schema and resolvers below) on `/graphql`, and the plant images on `/images/:id` (`images.ts`). Express is used instead of Apollo's standalone server, since that one can only serve GraphQL. - `schema.ts` defines the GraphQL schema (`typeDefs`). - `resolvers/` has the resolvers, split like the GraphQL operations in the frontend: `plants.ts` has the plant queries, `users.ts` has the user queries and mutations and validates user input, `helpers.ts` has the collections and helpers both use, and `index.ts` puts them together. - `queryBuilders.ts` builds the MongoDB filters and sort stages for searching, filtering and sorting plants on Explore Plants and My Matches, and the counts of how many plants each filter value would give. @@ -253,14 +254,13 @@ When the app starts, `UserProvider` reads `userId` from `localStorage` and runs ## Limitations of the architecture -- **Plant images are stored as base64 in the database.** Each plant image is stored as a base64 data URI in `imageData` (see [Data source: the Perenual API](#data-source-the-perenual-api)), instead of as an image file on the VM. This limits how well the solution scales: - - **More space:** Base64 turns every 3 bytes into 4 characters, so an image takes about 33% more space than the same file on disk. This makes the database larger, and the difference grows with every plant that is added. - - **Larger responses:** The resolver returns `imageData` in the `imageURL` field, so the images are sent inside the GraphQL response. A page of 12 plants therefore contains 12 full images, and the response cannot be returned before all of them are included. The browser cannot start loading one image while it waits for the rest, or skip images that are not visible. - - **Weaker caching:** Image files could be cached by the browser and Apache, and reused across pages and visits. The base64 strings are instead stored in the Apollo cache together with the rest of the data, and are downloaded again each time a query is not answered from the cache. +- **Plant images are stored as base64 in the database.** Each plant image is stored as a base64 data URI in `imageData` (see [Data source: the Perenual API](#data-source-the-perenual-api)), instead of as an image file on the VM. - **Why we chose it anyway:** The image URLs from Perenual expire after 24 hours, so the images had to be stored by us. Storing them in the same document as the rest of the plant data was the simplest solution: the seed script writes everything to MongoDB in one step, the backend and the frontend need no extra setup to serve or find image files, and the image always belongs to the right plant, since the plant and its image are stored and deleted together. With the 120 plants in our database, and a reasonable number more, the extra space and larger responses are acceptable, and pagination keeps each response limited to one page. + **Why:** The image URLs from Perenual stop working after 24 hours, so we had to store the images ourselves. We chose the database over image files on the VM, since the seed script then writes everything in one step, the image is stored and deleted together with its plant, and the VM needs no extra setup. - **How it could be improved:** If the collection grows much larger, the images should be stored as files on the VM (or in a separate file storage) and served by Apache, with only the path stored in MongoDB. The images would then take less space, be cached by the browser, and load separately from the plant data. + **How they are sent:** The GraphQL responses only contain a link, `/images/`, and `images.ts` sends the image as a file from that route. The browser keeps it for a week (`Cache-Control`) and the plant cards load it lazily (`loading="lazy"`). The plant queries no longer read `imageData`, only whether there is one. Before, the images were sent as base64 inside the GraphQL responses (see the measurement in [Sustainable web development](quality.md#sustainable-web-development)). + + **What is left:** The images still take about 33 % more space in the database than as files, and the backend decodes them on every request the browser has not cached. With many more plants, they should be stored as files with only the path in MongoDB. The `/images/:id` route could then be changed without changing the frontend. ## Data source: the Perenual API @@ -293,7 +293,7 @@ T03-Project-2/ │ │ ├── migrations.ts # Updates old data when the server starts │ │ ├── resolvers/ # GraphQL resolvers: plants.ts, users.ts, shared helpers.ts and index.ts │ │ ├── schema.ts # GraphQL schema -│ │ ├── server.ts # Starts Apollo Server +│ │ ├── server.ts # Starts the backend (app.ts: Express with /graphql and /images) │ │ └── types.ts # TypeScript types for documents, GraphQL types and arguments │ ├── tests/ # Backend tests against an in-memory MongoDB (db, server, indexes), with their own tsconfig.json │ ├── seedDataFetch.js # Script that fetches plant data from the Perenual API and stores it in MongoDB diff --git a/docs/quality.md b/docs/quality.md index e62f1f8d..9e9f58c0 100644 --- a/docs/quality.md +++ b/docs/quality.md @@ -105,6 +105,16 @@ We considered sustainability through both our design choices and our approach to The pictures were more than half of what the Profile page downloads, so this was the biggest single saving for that page. +- **Plant images as separate files:** The plant images are no longer sent as base64 inside the GraphQL responses, but as files from their own route, which the browser can cache and lazy-load (see [Limitations of the architecture](architecture.md#limitations-of-the-architecture)). Measured on page 1 of Explore Plants (12 plants, 9 with an image), with the cache turned off and after scrolling to the bottom: + + | | Before | After | Change | + | ---------------- | ------------------- | ------- | ------ | + | GraphQL response | 338 kB | 11.9 kB | −96 % | + | Plant images (9) | inside the response | 247 kB | | + | Total | 338 kB | 259 kB | −23 % | + + The page still downloads the same images. The −96 % only shows that they moved out of the GraphQL response; the real saving is the −23 % in total, since a file is about a quarter smaller than the same image as base64. Caching and lazy loading are not part of the measurement, so the saving is larger in normal use. + ## Design choices - **Color palette and contrast:** We used a limited color palette to maintain a consistent visual identity across the application. We also checked the contrast between our chosen colors to help ensure that text and other interface elements remain distinguishable and in line with accessibility requirements. See [Accessibility](#accessibility). diff --git a/docs/tests.md b/docs/tests.md index a15322f1..6b68d517 100644 --- a/docs/tests.md +++ b/docs/tests.md @@ -148,7 +148,10 @@ The tests are in `frontend/src/tests`. Snapshot tests are only used for small co - Best match first: only offered when the user has preferences, saved for the session, and newest first when it was saved but the user has no preferences any more. - `NotFoundPage.test.tsx` - An unknown path shows the 404 page, with a link back to Plant Match. +- `apiUrl.test.ts` + - An image path from the backend is resolved against the API's address, and a full URL is kept as it is. - `PlantCard.test.tsx` + - The plant image is loaded from the backend's address and lazily (`loading="lazy"`). - The back of the card shows the whole plant after clicking information, missing facts and images are shown as unknown, watering, sunlight and care level are turned into the right preference chips, and the values on the back are translated in any casing (with "Moderate" as medium), while unknown values are shown as they are. - `PlantMatchPage.test.tsx` - The instructions and the first plant, going to the next plant with like and dislike and the empty card at the end, that a liked plant is saved as a match and a skipped one is not, the loading and error states, that preferences saved on the profile are highlighted on the card and also said in text for screen readers, and that the info button is described by the instructions, which Escape hides. @@ -196,7 +199,8 @@ The tests are in `backend/tests`. They use a real MongoDB in memory, started in - Connecting to the database in `MONGODB_URI` and `DB_NAME`, using `iloveplants` when `DB_NAME` is not set, and the error messages when `MONGODB_URI` is missing or empty, is not a MongoDB address, or MongoDB cannot be reached (for example when the SSH tunnel is down). - `server.test.ts` - Starting the server: the default port 3001, the port in `PORT`, and stopping with the error when the port is in use. - - Plants: `getPlants` returns the plants that match the most of the user's preferences first, also when they are fetched in batches ("Low" counts as easy care), random plants when there are no preferences or only unknown ones, and leaves out the plants in `excludeIds` (returning none when all are excluded). Also stored image data before the image URL, and in `explorePlants` the default sorting, case-insensitive search across common and scientific names with special characters read as text, the watering, care level and sunlight filters ("Medium" and "Moderate" count as the same care level), pagination with the total count, that `limit` and `offset` are kept within valid bounds (at most 50 plants per request), and all sort orders including best match first (by the preferences sent, by name when plants match equally well, and by name without preferences), and the match counts for every filter value (with the search and the other filters, but not the filter's own choice). + - Plant images: `/images/:id` sends the stored image as a file (the bytes, not base64) with its type and a `Cache-Control` header, answers 404 for a plant without an image, an unknown plant and a malformed id, and GraphQL is served on `/graphql`. + - Plants: `getPlants` returns the plants that match the most of the user's preferences first, also when they are fetched in batches ("Low" counts as easy care), random plants when there are no preferences or only unknown ones, and leaves out the plants in `excludeIds` (returning none when all are excluded). Also that the plant queries link to the stored image (`/images/`) before the image URL and never send the base64 image, and in `explorePlants` the default sorting, case-insensitive search across common and scientific names with special characters read as text, the watering, care level and sunlight filters ("Medium" and "Moderate" count as the same care level), pagination with the total count, that `limit` and `offset` are kept within valid bounds (at most 50 plants per request), and all sort orders including best match first (by the preferences sent, by name when plants match equally well, and by name without preferences), and the match counts for every filter value (with the search and the other filters, but not the filter's own choice). - Users: creating and fetching users, updating the profile (trimming text, storing empty text and `null` as `null`, and only changing the sent fields), the plant owner test results as profile pictures, preferences without duplicates, and adding and removing matches in order. - My matches: `myMatches` sorts by newest (the default), oldest, A–Z, Z–A and best match first (by the user's saved preferences), returns one page at a time with the total count, leaves out and does not count matched plants that were deleted, and returns an empty page for a user without matches and for an unknown or malformed user id. Filtering and searching only among the user's matches, with the filter counts also counted only among them, and zero counts for a user without matches. - Error messages: invalid input gives the right message and the code `BAD_USER_INPUT` and saves nothing (too long name or description, unknown profile picture, unknown preferences, unknown or malformed plant ids), invalid GraphQL requests give the right error, and the server passes on a database error and keeps running. diff --git a/frontend/src/components/plantCard/PlantCard.tsx b/frontend/src/components/plantCard/PlantCard.tsx index 99c170cb..80a25347 100644 --- a/frontend/src/components/plantCard/PlantCard.tsx +++ b/frontend/src/components/plantCard/PlantCard.tsx @@ -3,6 +3,7 @@ import type { KeyboardEvent } from "react"; import { useTranslation } from "react-i18next"; import PlantPreferenceChips from "../plantPreferenceChips/PlantPreferenceChips"; import type { Plant } from "../../types/Plant"; +import { toImageUrl } from "../../graphql/apiUrl"; import { traitLabel } from "./plantTraits"; import "./PlantCard.css"; @@ -81,10 +82,14 @@ export default function PlantCard({

{name}

{imageURL ? ( + // The image is a file on the backend, so the browser can cache + // it, and lazy loading only fetches it when the card is near + // the screen, e.g. not for cards far down on Explore Plants {plantName} ) : (
. They are on the same server as the API, so the path is resolved +// against the API's address, not the page's. A full URL is kept as it is. +export function toImageUrl(path: string): string { + return new URL(path, new URL(GRAPHQL_URL, window.location.href)).href; +} diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 3eb48848..059304ee 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -7,9 +7,10 @@ import App from "./App"; import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client"; import { ApolloProvider } from "@apollo/client/react"; import { UserProvider } from "./context/UserContext"; +import { GRAPHQL_URL } from "./graphql/apiUrl"; const client = new ApolloClient({ - link: new HttpLink({ uri: import.meta.env.VITE_GRAPHQL_URL ?? "/graphql" }), + link: new HttpLink({ uri: GRAPHQL_URL }), cache: new InMemoryCache({ typePolicies: { User: { diff --git a/frontend/src/tests/PlantCard.test.tsx b/frontend/src/tests/PlantCard.test.tsx index 0cddc283..f650c6c3 100644 --- a/frontend/src/tests/PlantCard.test.tsx +++ b/frontend/src/tests/PlantCard.test.tsx @@ -40,7 +40,7 @@ describe("PlantCard", () => { { />, ); - expect(screen.getByRole("img", { name: "Orchid" })).toHaveAttribute( + // The path from the backend is resolved against the API's address, and the + // image is only loaded when the card is near the screen + const image = screen.getByRole("img", { name: "Orchid" }); + expect(image).toHaveAttribute( "src", - "orchid.png", + new URL("/images/1", window.location.href).href, ); + expect(image).toHaveAttribute("loading", "lazy"); await user.click( screen.getByRole("button", { name: "plantCard.tapForDetails" }), diff --git a/frontend/src/tests/apiUrl.test.ts b/frontend/src/tests/apiUrl.test.ts new file mode 100644 index 00000000..0fb70bfb --- /dev/null +++ b/frontend/src/tests/apiUrl.test.ts @@ -0,0 +1,17 @@ +import { describe, it, expect } from "vitest"; +import { toImageUrl } from "../graphql/apiUrl"; + +describe("toImageUrl", () => { + it("resolves an image path from the backend against the API's address", () => { + // In the tests the API is at /graphql on the page's own address + expect(toImageUrl("/images/abc")).toBe( + new URL("/images/abc", window.location.href).href, + ); + }); + + it("keeps a full URL as it is", () => { + expect(toImageUrl("https://example.com/plant.jpg")).toBe( + "https://example.com/plant.jpg", + ); + }); +}); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 3c8f29cb..79b1786f 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -17,6 +17,8 @@ export default defineConfig({ server: { proxy: { "/graphql": "http://localhost:3001", + // The plant images are sent by the backend too + "/images": "http://localhost:3001", }, }, });