From f83ce1ed230c4d47d24aa55a75b03e831c1842f3 Mon Sep 17 00:00:00 2001 From: Narai-1008 Date: Thu, 28 May 2026 06:36:10 +0000 Subject: [PATCH 1/3] =?UTF-8?q?MongoDB=E7=92=B0=E5=A2=83=E6=A7=8B=E7=AF=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/Dockerfile | 25 ++++++++++++++++++++++ .devcontainer/devcontainer.json | 35 +++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 36 ++++++++++++++++++++++++++++++++ package-lock.json | 26 +++++++++++------------ package.json | 2 +- 5 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..398c7004 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,25 @@ +FROM mcr.microsoft.com/devcontainers/javascript-node:4-24-bookworm + +# Install MongoDB command line tools - though mongo-database-tools not available on arm64 +ARG MONGO_TOOLS_VERSION=6.0 +RUN . /etc/os-release \ + && curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \ + && apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get install -y mongodb-mongosh \ + && if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node modules +# RUN su node -c "npm install -g " + + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..7d7205a2 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-mongo +{ + "name": "Node.js & Mongo DB", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "mongodb.mongodb-vscode", + "streetsidesoftware.code-spell-checker" + ] + } + }, + "features": { + "ghcr.io/devcontainers-extra/features/jshint:2": {} + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [3000, 27017], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "npm install" + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..b7ba686b --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: mongo:latest + restart: unless-stopped + volumes: + - mongodb-data:/data/db + + # Uncomment to change startup options + # environment: + # MONGO_INITDB_ROOT_USERNAME: root + # MONGO_INITDB_ROOT_PASSWORD: example + # MONGO_INITDB_DATABASE: your-database-here + + # Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + mongodb-data: \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8b612d5c..d588169b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "helmet": "^8.1.0", "http-errors": "^2.0.0", "luxon": "^3.6.1", - "mongoose": "^9.2.1", + "mongoose": "^9.6.3", "morgan": "^1.10.0", "pug": "^3.0.3" }, @@ -1300,9 +1300,9 @@ } }, "node_modules/kareem": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-3.2.0.tgz", - "integrity": "sha512-VS8MWZz/cT+SqBCpVfNN4zoVz5VskR3N4+sTmUXme55e9avQHntpwpNq0yjnosISXqwJ3AQVjlbI4Dyzv//JtA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-3.3.0.tgz", + "integrity": "sha512-kpSuLD3/7RenBnjnJdOHXCKC8dTd1JzeOiJhN0necWWci6cC+qX+VuwPnMVgb+a4+KNJSfgqahpnfWaeDXCimw==", "license": "Apache-2.0", "engines": { "node": ">=18.0.0" @@ -1553,13 +1553,13 @@ } }, "node_modules/mongoose": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.2.1.tgz", - "integrity": "sha512-fmNLwgct5km7iL1MqvTMncarR1E1TIw2lmc9A4UoDVdS7AQe95K+DnRK0qATkSUdwUC9V/5wlDcqnkQQjbSRkA==", + "version": "9.6.3", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.6.3.tgz", + "integrity": "sha512-vI6dTTlQnfMCyyQ5TrvhG0bCRs4dq5e1uFNPtOOWsOhn0fSg8AoIHjfyyCYr8aybyvPs845dRHGxsC3w/fHcBA==", "license": "MIT", "dependencies": { - "kareem": "3.2.0", - "mongodb": "~7.0", + "kareem": "3.3.0", + "mongodb": "~7.2", "mpath": "0.9.0", "mquery": "6.0.0", "ms": "2.1.3", @@ -1592,13 +1592,13 @@ } }, "node_modules/mongoose/node_modules/mongodb": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz", - "integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.2.0.tgz", + "integrity": "sha512-F/2+BMZtLVhY30ioZp0dAmZ+IRZMBqI+nrv6t5+9/1AIwCa8sMRC3jBf81lpxMhnZgqq8CoUD503Z1oZWq1/sw==", "license": "Apache-2.0", "dependencies": { "@mongodb-js/saslprep": "^1.3.0", - "bson": "^7.0.0", + "bson": "^7.2.0", "mongodb-connection-string-url": "^7.0.0" }, "engines": { diff --git a/package.json b/package.json index 673317c1..a57f11a9 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "helmet": "^8.1.0", "http-errors": "^2.0.0", "luxon": "^3.6.1", - "mongoose": "^9.2.1", + "mongoose": "^9.6.3", "morgan": "^1.10.0", "pug": "^3.0.3" }, From 76d0c1aa76e47d6ca4571e19fdd0d7b99cce3aa5 Mon Sep 17 00:00:00 2001 From: Narai-1008 Date: Thu, 28 May 2026 06:46:25 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E3=82=B5=E3=83=BC=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=81=AA=E3=81=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 2 +- package-lock.json | 7 +++++++ package.json | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 7e4c3155..f898798f 100644 --- a/app.js +++ b/app.js @@ -27,7 +27,7 @@ app.set("views", path.join(__dirname, "views")); app.set("view engine", "pug"); app.use(logger("dev")); -app.use(express.json()); +mongodb://localhost:27017/local_library app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); diff --git a/package-lock.json b/package-lock.json index d588169b..9e6f32b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "express-locallibrary-tutorial", "version": "0.0.1", "dependencies": { + "async": "^3.2.6", "compression": "^1.8.0", "cookie-parser": "^1.4.7", "debug": "^4.4.1", @@ -194,6 +195,12 @@ "integrity": "sha512-5oJg84os6NMQNl27T9LnZkvvqzvAnHu03ShCnoj6bsJwS7L8AO4lf+C/XjK/nvzEqQB744moC6V128RucQd1jA==", "license": "MIT" }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "license": "MIT" + }, "node_modules/async-mutex": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz", diff --git a/package.json b/package.json index a57f11a9..0d02ee01 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "test": "node --test" }, "dependencies": { + "async": "^3.2.6", "compression": "^1.8.0", "cookie-parser": "^1.4.7", "debug": "^4.4.1", From 52b144ffc614e1b16b7998ff349207252f108209 Mon Sep 17 00:00:00 2001 From: Narai-1008 Date: Thu, 28 May 2026 07:12:14 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index f898798f..f9a20161 100644 --- a/app.js +++ b/app.js @@ -20,14 +20,14 @@ const limiter = RateLimit({ max: 60, }); // Apply rate limiter to all requests -app.use(limiter); +mongodb://localhost:27017/local_library // view engine setup app.set("views", path.join(__dirname, "views")); app.set("view engine", "pug"); app.use(logger("dev")); -mongodb://localhost:27017/local_library +app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use(cookieParser());