{"id":27854855,"url":"https://github.com/genaker/nodejs-image-server","last_synced_at":"2025-06-14T14:39:05.999Z","repository":{"id":277970629,"uuid":"933950924","full_name":"Genaker/nodejs-image-server","owner":"Genaker","description":"Node JS server to generate resized webP images based on path or url. ","archived":false,"fork":false,"pushed_at":"2025-02-19T09:30:20.000Z","size":67,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-10T05:42:07.742Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/Genaker.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-02-17T02:51:10.000Z","updated_at":"2025-04-05T01:09:50.000Z","dependencies_parsed_at":"2025-02-17T10:04:11.995Z","dependency_job_id":"a97f2f75-3d43-4776-b6af-6869d8fc19b5","html_url":"https://github.com/Genaker/nodejs-image-server","commit_stats":null,"previous_names":["genaker/nodejs-image-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Genaker/nodejs-image-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2Fnodejs-image-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2Fnodejs-image-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2Fnodejs-image-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2Fnodejs-image-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Genaker","download_url":"https://codeload.github.com/Genaker/nodejs-image-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2Fnodejs-image-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259833463,"owners_count":22918923,"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":[],"created_at":"2025-05-04T09:59:13.343Z","updated_at":"2025-06-14T14:39:05.991Z","avatar_url":"https://github.com/Genaker.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js Image Server with Fastify \u0026 Nginx\nThis image processing server is built using Fastify and integrates with Nginx to handle:\n\n* Serving static images\n* Processing images dynamically (resize, convert, compress)\n* Handling both Local Files \u0026 Remote URLs\n* Caching processed images\n* Decoding Base64 paths for secure file access\n\n## Nginx Handles Static \u0026 Processed Images\nIf an image exists, it is served directly.\nIf an image is requested in Base64 format, Nginx forwards it to Fastify for decoding.\n\n# Fastify Processes Images \u0026 Caches Them\n* Accepts image processing parameters (format, quality, width, height).\n* Resizes, compresses, and converts images using sharp.\n* Stores processed images in /compressed_images/ for faster retrieval.\n* URLs can contain Base64-encoded paths (to prevent direct file access).\n* Fastify decodes Base64 paths and securely serves images.\n\n# Features\n - Fastify Server: Handles image requests dynamically\n - Sharp Image Processing: Resizes, compresses, and converts images\n - Handles URLs \u0026 Local Files: Works with remote \u0026 local images\n - Nginx for Static Files: Improves performance \u0026 caching\n - Base64 Secure Paths: Protects direct file access\n - Cron Auto-Cleanup: Deletes old images automatically\n - Jest Tests: Ensures reliability with automated tests\n\n# Install \n\n```\nsudo apt install npm\n#npm init -y\nnpm install\n\n```\n\nIf you are running the TypeScript version:\n\n```\nnpm run dev\n```\nOr, to build and run the compiled JavaScript version for production :\n```\nnpm run build\nnpm start\n```\n\nnpx tsc \u003e Compile TS to JS\nnode dist/server.js\t\u003e Run compiled JS server\nnpm run dev\t\u003e Run TS directly (no build)\nnpm run build \u003e Compile TS (tsc)\nnpm start \u003e\tRun compiled JS (node dist/server.js)\nnpx tsc --watch\t\u003e Auto-compile on file changes\n\n# Check server \nsudo apt install net-tools\nnetstat -tulnp | grep :8080\ncurl -I http://127.0.0.1:8080\ncurl -i http://127.0.0.1:8080\n\n# Nginx Node JS server integration\n\n```\n#node js image resizing snippet\nset $COMPRESSED_IMAGES /nodejs-image-server/compressed_images/;\n\nlocation /media/2/ {\n        rewrite ^/media/2/(.*)$ /$1 break;\n        set $image_path \"$MAGE_ROOT$COMPRESSED_IMAGES$1\";\n        try_files $image_path @nodejs;\n}\n\nlocation @nodejs {\n        proxy_pass http://127.0.0.1:8080$request_uri;\n        proxy_set_header Host $host;\n        proxy_set_header X-Original-URI $request_uri;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto $scheme;\n}\n#node js snippet end\n```\n\n## Magento config \nprivate const XML_PATH_CATALOG_MEDIA_URL_FORMAT = 'web/url/catalog_media_url_format';\npublic const IMAGE_OPTIMIZATION_PARAMETERS = 'image_optimization_parameters';\npublic const HASH = 'hash';\n```\nphp bin/magento config:set web/url/catalog_media_url_format image_optimization_parameters #hash\n```\n## Or replace default magento media static\ninsert this into \u003cbr\u003e\n\n**location /media/ {**\n\n```\nset $COMPRESSED_IMAGES /nodejs-image-server/compressed_images/;\n\nlocation ~* ^/media/catalog/.* {\n        rewrite ^/media/(.*)$ /$1 break;\n        set $image_path \"$MAGE_ROOT$COMPRESSED_IMAGES$1\";\n        \n        #Path Sample: nodejs-image-server/compressed_images/catalog/product/u/g/ug07-bk-0-f_webp-q_99-w_500-h_500-a_stretch.jpg\n        # If the file exists, set a custom header before serving\n        add_header X-Debug-Full-Path \"$image_path\" always;\n\n        if (-f $image_path) {\n            add_header X-Served-By \"Nginx-Static-Cache\" always;\n        }\n        try_files $image_path @nodejs;\n}\n````\n\nBut the same @nodejs\n\n## Running as a proces\n```\nsudo npm install -g pm2\npm2 start server.js --name myserver\npm2 save\npm2 startup\n## Remove from startup\n# pm2 unstartup \n## stop process\n# pm2 stop myserver\n```\n\n#NVM \n```\ncurl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash\nsource ~/.bashrc   # For Bash\nsource ~/.zshrc    # For Zsh\nsource ~/.profile  # Alternative (if the above don't work)\n\nnvm install node\nnvm use v23\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenaker%2Fnodejs-image-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenaker%2Fnodejs-image-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenaker%2Fnodejs-image-server/lists"}