Giter VIP home page Giter VIP logo

ezing / cloudcms-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gitana/cloudcms-server

0.0 2.0 0.0 3.81 MB

Cloud CMS application server module for Node.js / Express. This module provides middleware for virtualized content retrieval, cluster-wide caching and broadcasting, tag processing and much more. It is available to be used in building Node.js-based applications that run against Cloud CMS.

Home Page: https://www.cloudcms.com

License: Other

JavaScript 99.42% HTML 0.58%

cloudcms-server's Introduction

cloudcms-server

A Node.js module that provides a framework and server-side functionality for Cloud CMS deployed Node.js applications. This module provides the backbone capabilities for the application server tier of Cloud CMS as hosted at cloudcms.net.

For more information on Cloud CMS, please visit https://www.cloudcms.com.

Configuration

The start method takes a configuration object that enables, disables and provides settings for any underlying services.

This looks like:

{
    "setup": "single", // single, multiple, cluster
    "name": "Cloud CMS Application Server",
    "socketFunctions": [],
    "routeFunctions": [],
    "errorFunctions": [],
    "configureFunctions": {},
    "beforeFunctions": [],
    "afterFunctions": [],
    "reportFunctions": [],
    "dustFunctions": [],
    "initFunctions": [],
    "viewEngine": "handlebars",
    "storeEngines": {
        "app": {
            "type": "fs",
            "config": {
                "basePath": "{appBasePath}"
            }
        },
        "tmp": {
            "type": "fs",
            "config": {
                "basePath": "{tmpdirPath}/hosts/{host}",
                "hostsPath": "{tmpdirPath}/hosts"
            }
        },
        "hosts_fs": {
            "type": "fs",
            "config": {
                "basePath": "/hosts/{host}",
                "hostsPath": "/hosts"
            }
        },
        "hosts_s3": {
            "type": "s3",
            "config": {
                "accessKey": "",
                "secretKey": "",
                "bucket": "",
                "basePath": "/hosts/{host}",
                "hostsPath": "/hosts"
            }
        },
        "hosts_s3fs": {
            "type": "s3fs",
            "config": {
                "accessKey": "",
                "secretKey": "",
                "bucket": "",
                "basePath": "/hosts/{host}",
                "hostsPath": "/hosts"
            }
        }
    },
    "storeConfigurations": {
        "default": {
            "root": "app",
            "config": "app",
            "web": "app",
            "content": "tmp",
            "templates": "app",
            "modules": "app"
        },
        "oneteam": {
            "root": "hosts_fs",
            "config": "app",
            "web": "app",
            "content": "hosts_fs",
            "templates": "app",
            "modules": "hosts_fs"
        },
        "net-development": {
            "root": "hosts_fs",
            "config": "hosts_fs",
            "web": "hosts_fs",
            "content": "hosts_fs",
            "templates": "hosts_fs",
            "modules": "hosts_fs"
        },
        "net-production": {
            "root": "hosts_s3fs",
            "config": "hosts_s3fs",
            "web": "hosts_s3fs",
            "content": "hosts_s3fs",
            "templates": "hosts_s3fs",
            "modules": "hosts_s3fs"
        },
        "net-development-s3": {
            "root": "hosts_s3",
            "config": "hosts_s3",
            "web": "hosts_s3",
            "content": "hosts_s3",
            "templates": "hosts_s3"
        },
        "net-development-s3fs": {
            "root": "hosts_s3fs",
            "config": "hosts_s3fs",
            "web": "hosts_s3fs",
            "content": "hosts_s3fs",
            "templates": "hosts_s3fs",
            "modules": "hosts_s3fs"
        }
    },
    "duster": {
        "fragments": {
            "cache": true
        }
    },
    "virtualHost": {
        "enabled": false
    },
    "wcm": {
        "enabled": false,
        "cache": false
    },
    "serverTags": {
        "enabled": false
    },
    "insight": {
        "enabled": false
    },
    "perf": {
        "enabled": true
    },
    "driverConfig": {
        "enabled": true
    },
    "virtualDriver": {
        "enabled": false
    },
    "virtualContent": {
        "enabled": true
    },
    "flow": {
        "enabled": false
    },
    "form": {
        "enabled": true
    },
    "auth": {
        "enabled": true,
        "providers": {
            "facebook": {
                "enabled": false
            },
            "twitter": {
                "enabled": false
            },
            "linkedin": {
                "enabled": false
            }
        }
    },
    "notifications": {
        "enabled": false,
        "type": "sqs",
        "configuration": {
            "queue": "",
            "accessKey": "",
            "secretKey": "",
            "region": ""
        }
    },
    "broadcast": {
        "enabled": true
    },
    "local": {
        "enabled": true
    },
    "welcome": {
        "enabled": true,
        "file": "index.html"
    },
    "config": {
        "enabled": true
    },
    "cache": {
        "enabled": true
    },
    "templates": {
        "enabled": true
    },
    "modules": {
        "enabled": true
    },
    "debug": {
        "enabled": false,
        "logGlobalTimings": false
    },
    "cors": {
        "enabled": true,
        "origin": null,
        "methods": "GET, POST, PUT, DELETE, OPTIONS",
        "headers": "X-Forwarded-Host, X-Requested-With, Content-Type, Authorization, Origin, X-Requested-With, X-Prototype-Version, Cache-Control, Pragma, X-CSRF-TOKEN, X-XSRF-TOKEN",
        "credentials": false
    }
}

Environment Variables

The following environment variables can be set to control the server's configuration from the container level:

Virtual Driver Service

The virtual driver configuration is used to connect to Cloud CMS and request gitana driver credentials based on the incoming domain name. These parameters override any settings provided for the virtualDriver service block:

  • CLOUDCMS_VIRTUAL_DRIVER_BASE_URL
  • CLOUDCMS_VIRTUAL_DRIVER_CLIENT_KEY
  • CLOUDCMS_VIRTUAL_DRIVER_CLIENT_SECRET
  • CLOUDCMS_VIRTUAL_DRIVER_AUTHGRANT_KEY
  • CLOUDCMS_VIRTUAL_DRIVER_AUTHGRANT_SECRET

Broadcast Service

The broadcast service provides a communication and notification facility between nodes in the application server cluster. The cluster is elastic and may grow and shrink in size as demand increases and decreases. The type can be either noop (disabled) or redis.

  • CLOUDCMS_BROADCAST_TYPE
  • CLOUDCMS_BROADCAST_REDIS_PORT
  • CLOUDCMS_BROADCAST_REDIS_ENDPOINT

Cache Service

The cache service provides a cluster-wide cache accessible from any node or process in the cluster. The type can be either memory or redis.

  • CLOUDCMS_CACHE_TYPE
  • CLOUDCMS_CACHE_REDIS_PORT
  • CLOUDCMS_CACHE_REDIS_ENDPOINT

Hosting Modes

The server supports three hosting modes: standalone, single virtual tenant, multiple virtual tenants

Standalone

By default, the server will start up in standalone hosting mode. This is intended for a standalone web application with a local gitana.json file. The incoming host name is considered to be irrelevant and all on-disk caching is done against a "local" virtual host. In essence, no matter what the host name is, the same virtual host is considered.

In this mode, there is no support for virtual driver retrieval. You must supply the gitana.json locally.

To change the name of the "local" virtual host name, set CLOUDCMS_STANDALONE_HOST environment variable. The default is "local".

Single Virtual Tenant

In single virtual tenant mode, all incoming request, no matter the host, are mapped to a single Cloud CMS tenant's application deployment.

The virtual driver will retrieve the gitana.json for this tenant and maintain it over time. If the gitana.json API keys change on the server, they will be retrieved and used by the app server automatically.

To use this mode, set the following:

CLOUDCMS_VIRTUAL_HOST

This should be set to the host of the Cloud CMS application deployment.

Multiple Virtual Tenants

In multiple virtual tenants mode, all incoming requests have their incoming hosts considered. Each host may describe a different Cloud CMS application deployment. For N hosts, there will be N Cloud CMS application instances. This mode is intended for cases where you wish to have a single application support N customers.

To use this mode, set the following

CLOUDCMS_VIRTUAL_HOST_DOMAIN

This should be set to a suffix domain that is wildcarded against. For example, if you set it to "company.com", then any incoming requests for ".company.com" will be served. Each request will check with Cloud CMS to make sure it has the proper gitana.json pulled down for the Cloud CMS application deployment with that host. Each host maintains it's own location on disk and is served back via virtual hosting.

Stores

For every request, underlying persistence stores are applied that automatically configure to read and write objects to the correct place, either a file system or S3. Performance caching and directory paths are figured out ahead of time so that each virtual host works against the correct storage location.

  • CLOUDCMS_STORE_CONFIGURATION
  • CLOUDCMS_STORE_S3_ACCESS_KEY
  • CLOUDCMS_STORE_S3_SECRET_KEY
  • CLOUDCMS_STORE_S3_BUCKET

GitHub

The module supports dynamic application deployment from GitHub or BitBucket. Application code is deployed into the virtual hosting directories and served from there.

  • CLOUDCMS_NET_GITHUB_USERNAME
  • CLOUDCMS_NET_GITHUB_PASSWORD
  • CLOUDCMS_NET_BITBUCKET_USERNAME
  • CLOUDCMS_NET_BITBUCKET_PASSWORD

Proxy

These settings configured where the /proxy endpoint points to be default.

GITANA_PROXY_HOST GITANA_PROXY_PORT GITANA_PROXY_SCHEME

Runtime

The module supports dynamic switching of the branch being served from. It also allows for the runtime cache buster value to be migrated at any time to allow for cache regeneration.

The following environment variables can be used to set up the initial state:

CLOUDCMS_RUNTIME_CB CLOUDCMS_RUNTIME_RELEASE_ID CLOUDCMS_RUNTIME_BRANCH_ID

A runtime.json file is written into each virtual host's content directory. It can be adjusted at runtime via a POST call to:

/_runtime/migrate

And the JSON payload should be:

{
    "branchId": "<newBranchId>",
    "releaseId": "<newReleaseId>",
    "cb": "<newCacheBusterValue>"
}

Only branchId is truly required. If cb is specified, it will be used, otherwise a new ID will be auto-generated.

Other Environment Variables

The following environments are computed automatically and available to services:

  • CLOUDCMS_APPSERVER_MODE: either 'development' or 'production', if not specified, derives from NODE_ENV
  • CLOUDCMS_APPSERVER_BASE_PATH: the startup location of the node process, applicable when running locally
  • CLOUDCMS_APPSERVER_PACKAGE_NAME: the name of the module currently beingrun (from package.json)
  • CLOUDCMS_APPSERVER_PACKAGE_VERSION: the version of the module currently being run (from package.json)
  • CLOUDCMS_APPSERVER_TIMESTAMP: the timestamp of server startup

node switches

Examples of Node switches:

node --max_old_space_size=3000 --prof nodemem.js --trace_incremental_marking=true --incremental_marking_steps=false

node --max_old_space_size=3000 --max_new_space_size=3000 --max_executable_size=1000 --gc_global --prof nodemem.js --noincremental_marking --nolazy_sweeping --never_compact --gc_global --gc_interval=100000000

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.