diff --git a/.devcontainer/data/library.tgz b/.devcontainer/data/library.tgz deleted file mode 100644 index 5192c88..0000000 Binary files a/.devcontainer/data/library.tgz and /dev/null differ diff --git a/.devcontainer/data/library/authors.bson b/.devcontainer/data/library/authors.bson new file mode 100644 index 0000000..a550c21 Binary files /dev/null and b/.devcontainer/data/library/authors.bson differ diff --git a/.devcontainer/data/library/authors.metadata.json b/.devcontainer/data/library/authors.metadata.json new file mode 100644 index 0000000..6bc33e0 --- /dev/null +++ b/.devcontainer/data/library/authors.metadata.json @@ -0,0 +1 @@ +{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"},"books":{"$numberInt":"1"}},"name":"_id_1_books_1"}],"uuid":"50ff33f70993455e8f6de0d8d4a1d194","collectionName":"authors","type":"collection"} \ No newline at end of file diff --git a/.devcontainer/data/library/books.bson b/.devcontainer/data/library/books.bson new file mode 100644 index 0000000..97ba45a Binary files /dev/null and b/.devcontainer/data/library/books.bson differ diff --git a/.devcontainer/data/library/books.metadata.json b/.devcontainer/data/library/books.metadata.json new file mode 100644 index 0000000..626046f --- /dev/null +++ b/.devcontainer/data/library/books.metadata.json @@ -0,0 +1 @@ +{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"ae0f303e615045f99fb3768b4deedd69","collectionName":"books","type":"collection"} \ No newline at end of file diff --git a/.devcontainer/data/library/issueDetails.bson b/.devcontainer/data/library/issueDetails.bson new file mode 100644 index 0000000..df6f3da Binary files /dev/null and b/.devcontainer/data/library/issueDetails.bson differ diff --git a/.devcontainer/data/library/issueDetails.metadata.json b/.devcontainer/data/library/issueDetails.metadata.json new file mode 100644 index 0000000..a4af06c --- /dev/null +++ b/.devcontainer/data/library/issueDetails.metadata.json @@ -0,0 +1 @@ +{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"9b7cc777cfe142c0ba97170ed2e8138e","collectionName":"issueDetails","type":"collection"} \ No newline at end of file diff --git a/.devcontainer/data/library/operations.bson b/.devcontainer/data/library/operations.bson new file mode 100644 index 0000000..bd1b616 Binary files /dev/null and b/.devcontainer/data/library/operations.bson differ diff --git a/.devcontainer/data/library/operations.metadata.json b/.devcontainer/data/library/operations.metadata.json new file mode 100644 index 0000000..d11e02b --- /dev/null +++ b/.devcontainer/data/library/operations.metadata.json @@ -0,0 +1 @@ +{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"9b7cc777cfe142c0ba97170ed2e8138e","collectionName":"operations","type":"collection"} \ No newline at end of file diff --git a/.devcontainer/data/library/reviews.bson b/.devcontainer/data/library/reviews.bson new file mode 100644 index 0000000..3b085d7 Binary files /dev/null and b/.devcontainer/data/library/reviews.bson differ diff --git a/.devcontainer/data/library/reviews.metadata.json b/.devcontainer/data/library/reviews.metadata.json new file mode 100644 index 0000000..785e228 --- /dev/null +++ b/.devcontainer/data/library/reviews.metadata.json @@ -0,0 +1 @@ +{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"},"bookId":{"$numberInt":"1"}},"name":"_id_1_bookId_1"}],"uuid":"3d74995d4b2e47fc80d0f95b46287e32","collectionName":"reviews","type":"collection"} \ No newline at end of file diff --git a/.devcontainer/data/library/users.bson b/.devcontainer/data/library/users.bson new file mode 100644 index 0000000..ea51f5b Binary files /dev/null and b/.devcontainer/data/library/users.bson differ diff --git a/.devcontainer/data/library/users.metadata.json b/.devcontainer/data/library/users.metadata.json new file mode 100644 index 0000000..b01a0da --- /dev/null +++ b/.devcontainer/data/library/users.metadata.json @@ -0,0 +1 @@ +{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"70201eb312854a1c8d2d91c434abb65c","collectionName":"users","type":"collection"} \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3e5627a..f3ca826 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,18 +1,24 @@ { - "image": "mcr.microsoft.com/devcontainers/universal:2", - "waitFor": "onCreateCommand", - "updateContentCommand": "/bin/bash .devcontainer/updateContent.sh", - "postCreateCommand": "", + "name": "MongoDB Library Sample App - Nodejs version", + "dockerComposeFile": "docker-compose.yml", + "service": "server", // container defined in docker-compose + "updateContentCommand": "bash .devcontainer/install-mongodb-db-tools.sh && bash .devcontainer/import.sh && bash .devcontainer/updateContent.sh", // included in prebuilt + // this will open 3 bash sessions, each one running the specified command "postAttachCommand": { "server": "cd server && npm start", "client": "export NG_CLI_ANALYTICS=\"false\"; cd client && npm start", - "portSetup": "/bin/bash .devcontainer/portSetup.sh" + "portSetup": "sleep 5 && .devcontainer/portSetup.sh" }, "customizations": { "codespaces": { "openFiles": [ "server/.env" ] + }, + "vscode": { + "extensions": [ + "mongodb.mongodb-vscode" + ] } }, "portsAttributes": { @@ -20,9 +26,17 @@ "label": "Client", "onAutoForward": "openPreview" }, - "5000": { + "50000": { "label": "Server" + }, + "27017": { + "label": "MongoDB Atlas" } }, - "forwardPorts": [4200, 5000] + "forwardPorts": [ + 4200, + 50000, + 27017 + ], + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}" } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..664bf61 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,35 @@ +services: + server: + image: mcr.microsoft.com/vscode/devcontainers/javascript-node:dev-16-bullseye + 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:mongodb + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + depends_on: + - mongodb + + mongodb: + image: mongodb/mongodb-atlas-local:8.0.3-20250506T093411Z + environment: + - MONGODB_INITDB_ROOT_USERNAME=admin + - MONGODB_INITDB_ROOT_PASSWORD=mongodb + - MONGO_INITDB_DATABASE=library + restart: unless-stopped + volumes: + - mongodb-data:/data/db + - ../..:/workspaces:cached + ports: + - 27017:27017 + + # 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/.devcontainer/import.sh b/.devcontainer/import.sh new file mode 100755 index 0000000..1981389 --- /dev/null +++ b/.devcontainer/import.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd .devcontainer/data + +# Import Library data WITHOUT embeddings + +mongorestore --uri mongodb://localhost:27017/library --username admin --password mongodb --drop --authenticationDatabase=admin library + diff --git a/.devcontainer/install-mongodb-db-tools.sh b/.devcontainer/install-mongodb-db-tools.sh new file mode 100755 index 0000000..57d90c4 --- /dev/null +++ b/.devcontainer/install-mongodb-db-tools.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Install MongoDB command line tools + +# We need to download MongoDB Database Tools to import data. In Linux we have two architectures: +# Linux identifies as amd64, in MongoDB the file has ARM64 for Mac M1 +# https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-arm64-100.11.0.tgz +# Linux identifies as aarch64, in MongoDB the file has x86_64 for intel +# https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-x86_64-100.11.0.tgz +# NOTE: changed Ubuntu version to 20.04, as 22.04 is not supported by the Image used in the devcontainer +# See: https://www.mongodb.com/community/forums/t/cant-run-mongorestore-with-glibc-2-31/267909 + +export MONGO_TOOLS_VERSION=100.11.0 +export ARCH=$(dpkg --print-architecture) +if [ $ARCH = "amd64" ]; then export TARGET_ARCH="x86_64"; else export TARGET_ARCH="arm64"; fi +export TARGET="mongodb-database-tools-ubuntu2004-${TARGET_ARCH}-${MONGO_TOOLS_VERSION}.deb" +echo "Installing tools for architecture $ARCH, linux/${TARGET_ARCH}, target file=${TARGET}" +echo "curl https://fastdl.mongodb.org/tools/db/${TARGET}" +curl "https://fastdl.mongodb.org/tools/db/${TARGET}" --output "${TARGET}" +sudo apt-get install -y "./${TARGET}" +rm "./${TARGET}" + +# Install mongosh + +# https://downloads.mongodb.com/compass/mongosh-2.4.0-linux-x64.tgz +# https://downloads.mongodb.com/compass/mongosh-2.4.0-linux-arm64.tgz + +echo "Installing mongosh" +if [ ARCH = "amd64" ]; then export MONGO_SHELL="mongosh-2.4.0-linux-x64"; else export MONGO_SHELL="mongosh-2.4.0-linux-arm64"; fi +curl "https://downloads.mongodb.com/compass/${MONGO_SHELL}.tgz" --output "${MONGO_SHELL}.tgz" +tar xvfz "${MONGO_SHELL}.tgz" +rm "./${MONGO_SHELL}.tgz" +sudo cp mongosh-2.4.0-linux-arm64/bin/* /usr/local/bin/ +rm -rf "./${MONGO_SHELL}" diff --git a/.devcontainer/portSetup.sh b/.devcontainer/portSetup.sh old mode 100644 new mode 100755 index 04bcdb9..926fc57 --- a/.devcontainer/portSetup.sh +++ b/.devcontainer/portSetup.sh @@ -1,2 +1,19 @@ -echo "Exposing port 5000" -gh codespace ports visibility 5000:public -c $CODESPACE_NAME \ No newline at end of file +if [ -z "$CODESPACE_NAME" ]; then + echo "Not running in a codespace, exiting." + exit +fi + +echo "Installing GH" + +(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \ +&& sudo mkdir -p -m 755 /etc/apt/keyrings \ +&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \ +&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ +&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ +&& sudo mkdir -p -m 755 /etc/apt/sources.list.d \ +&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ +&& sudo apt update \ +&& sudo apt install gh -y + +echo "Exposing ports" +gh codespace ports visibility 4200:public 27017:public 50000:public -c $CODESPACE_NAME \ No newline at end of file diff --git a/.devcontainer/updateContent.sh b/.devcontainer/updateContent.sh old mode 100644 new mode 100755 index d0f9e0d..1dc9343 --- a/.devcontainer/updateContent.sh +++ b/.devcontainer/updateContent.sh @@ -1,5 +1,7 @@ export NG_CLI_ANALYTICS="false" + cd client npm install cd ../server npm install + diff --git a/.husky/pre-commit b/.husky/pre-commit index 979c4aa..f2ea05a 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,6 +1,8 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +(cd .devcontainer && docker compose up) & +sleep 5 (cd server && npm run lint) (cd server && npm test) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fbf9ab4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "mdb.presetConnections": [ + { + "name": "Library DB", + "connectionString": "mongodb://admin:mongodb@localhost:27017" + } + ], + "mdb.showOverviewPageAfterInstall": false +} \ No newline at end of file diff --git a/README.md b/README.md index 0ee53f8..aec408c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This is a library management system built with the MEAN (MongoDB, Express, Angul **library/server/.env** ``` - PORT="5000" + PORT="50000" DATABASE_URI="mongodb+srv://:@m0.kwqkoewm.mongodb.net" DATABASE_NAME="library" SECRET="secret" diff --git a/client/src/app/config.ts b/client/src/app/config.ts index 2effc2d..a276d0d 100644 --- a/client/src/app/config.ts +++ b/client/src/app/config.ts @@ -1,4 +1,4 @@ -const backendPort = "5000"; +const backendPort = "50000"; const URL = `${location.protocol}//${location.hostname.replace('-4200', `-${backendPort}`)}${location.port ? `:${backendPort}` : ""}`; // const URL = `https://library-management-system-930413307030.us-central1.run.app/`; diff --git a/server/.env b/server/.env index 1545245..626f114 100644 --- a/server/.env +++ b/server/.env @@ -1,4 +1,4 @@ -PORT=5000 -DATABASE_URI=mongodb+srv://user:password@cluster +PORT=50000 +DATABASE_URI=mongodb://admin:mongodb@localhost:27017/?directConnection=true DATABASE_NAME=library SECRET=secret \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile deleted file mode 100644 index 1a595e2..0000000 --- a/server/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM node:18-slim -WORKDIR /usr/app - -# Install dependencies and build the project. -COPY package.json package-lock.json ./ -RUN npm install -COPY . . -RUN npm run build - -# Run the web service on container startup. -CMD ["node", "dist/server.js"]