{"id":27559145,"url":"https://github.com/oscargomezgonzalezz/mern-compose","last_synced_at":"2026-04-05T08:35:10.141Z","repository":{"id":286476840,"uuid":"961486677","full_name":"OscarGomezGonzalezz/MERN-compose","owner":"OscarGomezGonzalezz","description":"MERN application managed with docker-compose, containing a reverse proxy(nginx) and IAM tool (keycloak). Also docker-compose enabled","archived":false,"fork":false,"pushed_at":"2025-04-14T15:01:54.000Z","size":4940,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T23:33:03.831Z","etag":null,"topics":["docker","docker-compose","iam","keycloak","nginx"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OscarGomezGonzalezz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-06T16:14:56.000Z","updated_at":"2025-04-16T22:46:16.000Z","dependencies_parsed_at":"2025-04-06T18:42:51.698Z","dependency_job_id":"26a98aaa-55c5-467b-b587-62fd3b5d080c","html_url":"https://github.com/OscarGomezGonzalezz/MERN-compose","commit_stats":null,"previous_names":["oscargomezgonzalezz/mern-app-","oscargomezgonzalezz/mern-compose"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarGomezGonzalezz%2FMERN-compose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarGomezGonzalezz%2FMERN-compose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarGomezGonzalezz%2FMERN-compose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarGomezGonzalezz%2FMERN-compose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OscarGomezGonzalezz","download_url":"https://codeload.github.com/OscarGomezGonzalezz/MERN-compose/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249830836,"owners_count":21331355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","iam","keycloak","nginx"],"created_at":"2025-04-19T23:33:07.286Z","updated_at":"2025-12-30T21:57:42.502Z","avatar_url":"https://github.com/OscarGomezGonzalezz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TODO List App\n\n## Index\n\n- [Description](#description)\n- [Task 1: Local development with MongoDB and React](#task-1-local-development-with-mongodb-and-react)\n- [Task 2: Migrating to docker-compose, nginx and HTTPS setup](#task-2-migrating-to-docker-compose-nginx-and-https-setup)\n- [Task 3: Enabling Load Balancing to multiple backend replicas](#task-3-enabling-load-balancing-to-multiple-backend-replicas)\n  - [Development](#development)\n  - [Production](#production)\n  - [Kubernetes](#kubernetes)\n  - [TLS/HTTPS To Keycloak](#tlshttps-to-keycloak)\n\n---\n## Description\n\nTODO List App (MERN) with session management. Built using React for the frontend and Node.js for the backend with MongoDB. This guide covers local development, containerization with Docker, Kubernetes deployment, and HTTPS setup via Keycloak.\n\n---\n\n## Task 1: Local development with mongodb and react##\n\nFor running mongoDB in the cloud (mongoDB Atlas):\n1. Create a cluster\n2. create user and password(registered in the .env file)\n3. choose the driver connection \n\nBut as we have to run the database locally:\n1. Install mongoDB\n2. brew start mongodb-community\n3. For checking the connection in shell: mongosh \"mongodb+srv://clusterxxxxxx\" --apiVersion 1 --username username\n\nIMPORTANT: WHEN TESTING IT WITH POSTMAN:\nAuthorization: {token} \u003c--- WITHOUT ADDING \"Token\" OR \"Bearer\" before the token itself\n\nBefore inizialising the backend, we have to create a .env file, inside the /backend folder, with our secret key: JWT_SECRET=example\nFor security reasons, add this file to the .gitignore\n\nNow, we can run the backend: \n1. cd backend\n2. nodemon server.js\n\nNow, backend is ready for receiving requests from the frontend, so we run it with:\n1. cd ../frontend\n2. npm start\n\n## Task 2: Migrating to docker-compose, nginx and HTTPS setup##\n\n\n![Kubernetes Ingress Architecture](./assets/Cloud%20arch%20(5)%20(1).jpg)\n\n### Development\n\nFirst, we migrate the backend to a docker container:\n1. for testing just the node server (mongo running locally not in container), the uri should be:\n- docker build -t test .\n- docker run -d -p 3500:3500 test\n\nUpdate dbConnection.js with: \n- const uri = \"mongodb://host.docker.internal:27017/\"; \n\n2. Once we know node image is working, we migrate the database to a container, for so, instead of \n   creating another dockerfile for the db, we will directly create it in the docker-compose \n\n3. Then, we change the uri of the dbConnection.js to process.env ones, as these are defined in the .yml.\n\n4. Once full backend is tested and works, we have to integrate frontend. Before everything, we have to understand:\n\nIn task 1, When you run npm start, React uses Vite, webpack-dev-server, or React Scripts, depending on your setup.\nThis development server runs by default on localhost:3000 (unless it's taken).\nIt's only used during development and is not included in your production Docker image\n\nWhen you do this in the Dockerfile:\nRUN npm run build\nIt generates a static build of your React app in /build. Then, Nginx serves those files — and Nginx typically listens on port 80 inside the container, but we will use 3000\n\n5. Now we create the default.conf of nginx, forwarding requests to services, to its inside containers ips and add it too to the docker-compose\nadd also mongo-express for visualizaing db: ADMIN; PASS\n\nFOR SEEING APPLIED CHANGES IN NGINX .CONF WE HAVE TO REBUILD\n\n### Production\n\n6. test it in production env by creating dockerfiles of production and adding other nginx inside frontend\n\nLets build and push the image of our frontend and backend testing them with:\n- docker buildx build --platform linux/amd64,linux/arm64 -t your-dockerhub-username/your-image-name:tag . --push\nand then docker run\n\n\n## Task 3: Enabling Load Balancing to multiple backend replicas##\n\n![Kubernetes Ingress Architecture](./assets/Cloud%20arch.jpg)\n\nFOR CHECKING IF THE DIFFERENT SERVER MANAGEMENT WORKS WE CAN EXECUTE OPERATIONS SELECTING FOR EXAMPLE BACKEND 1, AND THEN IN DOCKER\nSEE HOW ITS LOGS ARE DIFFERENT FROM THE BACKEND 2\n\nBESIDES, IF WE SELECT THE LOAD BALANCED BACKEND, WE SEE HOW THE DIFFERENT WORKLOAD IS DISTRIBUTED (WITH ROUND ROBIN)\nBETWEEN BOTHS SERVERS\n\n\n\n\n\n\n\n\n\n\n\n\n## TLS/HTTPS ##\n### Certf x.509 for HTTPS\nTODO: see how apply X.509 to digital firm\n\nopenssl req -x509 -out localhostcert.pem -keyout localhostkey.pem \\ \n  -newkey rsa:2048 -nodes -sha256 \\\n  -subj '/CN=localhost' -extensions EXT -config \u003c( \\\n   printf \"[dn]\\nCN=localhost\\n[req]\\ndistinguished_name = dn\\n[EXT]\\nsubjectAltName=DNS:localhost\\nkeyUsage=digitalSignature\\nextendedKeyUsage=serverAuth\")\n\nwhen loading the secured page: https://localhost:443, we will have to set our local certificate as trusted\n\n### It is suggested to include the generated cert in your system, in MacOS:\nkeychain access-\u003eFile-\u003eimport cert-\u003eselect the cert in keychain access/login and set always trusr\n\n## Notes about Encryption and secure connections\n\n### 1WSSL (One-Way SSL) ###\nMeans only the server is authenticated by the client (usually a browser or another service).\nThis is what happens in most secure websites like https://google.com:\n1. The server shows its SSL/TLS certificate.\n2. The client (your browser) verifies it.\n3. If it's valid, a secure (encrypted) connection is established.\n\nCommon usage: Public HTPPS websites\n\n### 2WSSL (Two-Way SSL) or Mutual TLS ###\nMeans both the server and the client authenticate each other.\n\n1. The server presents its certificate (just like in 1WSSL).\n2. The client also presents its own certificate.\n3. The server verifies that the client's certificate is valid.\n4. If both are okay, the secure connection is established.\n\nCommon usage: Private APIs, internal services\n\n### 🔐 X.509 Certificates ###\nThese are the standard for public key certificates used in many cryptographic systems, including SSL/TLS. So when we talk about 1WSSL or 2WSSL, we're generally referring to X.509 certificates. These certificates contain:\n\n* A public key\n* Information about the entity (like the server or client)\n* A digital signature that confirms the certificate's authenticity.\n\nThe certificate is issued by a Certificate Authority (CA), but you can also create self-signed certificates for testing purposes (like the ones I created earlier).\n\n### ✉️ What is S/MIME? ###\nIt stands for Secure/Multipurpose Internet Mail Extensions. It’s a standard for sending encrypted and digitally signed emails using X.509 certificates.\n\n* Email Encryption: Encrypts the email content so only the intended recipient can read it. Prevents eavesdroppingª.\n* Digital Signature: Verifies that the email really came from the claimed sender. Ensures that the content hasn't been tamperedº with (message integrity).\n\nª: Eavesdropping means someone secretly listens in on your communication \nº: This means the message wasn't changed after it was sent.\n\nEach participant (sender and receiver) has an X.509 certificate with a public/private key pair.\nThe public key is usually shared via email clients or directories.\n\nExample:\nYou want to send Alice an encrypted email.\nAlice has an X.509 certificate with her public key.\nYou use that key to encrypt the email.\nOnly Alice, who has the matching private key, can decrypt it.\n\nIt’s supported by most major email clients:\n\nEmail Client\tS/MIME Support\nOutlook\t✅ Yes\nApple Mail\t✅ Yes\nThunderbird\t✅ Yes\nGmail (web)\t🚫 Not directly (needs 3rd party extension)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foscargomezgonzalezz%2Fmern-compose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foscargomezgonzalezz%2Fmern-compose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foscargomezgonzalezz%2Fmern-compose/lists"}