Giter Site home page Giter Site logo

mrspartak / granny-server-backend Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 528 KB

๐Ÿ‘ต Granny.js - Server app

License: MIT License

Dockerfile 0.50% JavaScript 99.50%
docker nodejs node-js app application picture picture-upload image-processing image-resizer image-manipulation

granny-server-backend's Introduction

Simple nodejs CDN server

This app supports uploading, delivering and manipulating images (resizing on the fly with cache)

Docker Cloud Automated build Docker Cloud Build Status Docker Pulls

Latest Github tag Join the chat at https://gitter.im/granny-js/community

Ecosystem

image

granny-server-backend - Backend service with API exposed to upload and serve/manipulate images
granny-js-client - Client library that works both in nodejs and browser. Makes API calls easier
granny-server-frontend - Frontend APP that uses client to manage your CDN domains and settings
granny-server-cron - Utility app

Sample usage

Let's say tou have new avatar to upload, and you want it to be avialable at path /users/sergio.jpeg
After you upload an image via API, the image is avialable at path cdn.example.com/i/users/sergio.jpeg
And now magic begins. Lets modify it! cdn.example.com/i/height=100,width=100/_/users/sergio.jpeg is of course resize on fly with cache

Resized image will be in cover mode. You can provide only one dimension too
- width || w: Number
- height || h: Number
- resize || r: String (100x100 || 100, 100x200)

Progressive image. Supported by jpeg, png
- progressive || pr: No value

Quality. Supported by jpeg, png, webp
- quality || q: Number [1-100]

Format to convert
- format || f: String [jpg|jpeg|png|webp]

Black and white
- bw: No value

Blur. Gaussian if number provided
- blur: No value or Number [1-1000]

Requirements

Environment variables

#port app will be launched at
const APP_PORT = process.env.APP_PORT || 3000
#mongo connection string
const MONGO = process.env.DEBUG || 'mongodb://localhost/js_cdn'
#S3 connection data
const S3_HOST = process.env.S3_HOST || '127.0.0.1'
const S3_PORT = process.env.S3_PORT || 9000
const S3_ACCESS_KEY = process.env.S3_ACCESS_KEY || 'minioadmin'
const S3_ACCESS_SECRET = process.env.S3_ACCESS_SECRET || 'minioadmin'
#start logging
const DEBUG = process.env.DEBUG || false

Docker

docker run -p 3000:3000 --name granny-server-backend \
  -e MONGO='mongodb://user@password:example.com/granny' \
  assorium/granny-server-backend:latest

Nginx

This an example Nginx config for all CDN.* subdomains All you need is to point your DNS A record to server IP and add domain via API or granny-server-frontend app This is only an example. I recommend to use real CDN service such as free CloudFlare before your app, and it will serve and cache all your images across the globe.

server {
    listen 80;
    charset UTF-8;
        
    server_name cdn.*;
    
    client_max_body_size 60m;
    
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-NginX-Proxy true;
    }
}

granny-server-backend's People

Contributors

dependabot-preview[bot] avatar gitter-badger avatar mrspartak avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

granny-server-backend's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.