{"id":16453423,"url":"https://github.com/blimmer/node-ember-cli-deploy-redis","last_synced_at":"2025-06-22T18:09:42.775Z","repository":{"id":32610305,"uuid":"36195455","full_name":"blimmer/node-ember-cli-deploy-redis","owner":"blimmer","description":"Easily fetch ember-cli-deploy revisions from redis in a node app","archived":false,"fork":false,"pushed_at":"2022-02-11T00:28:12.000Z","size":132,"stargazers_count":13,"open_issues_count":3,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-21T11:56:00.903Z","etag":null,"topics":[],"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/blimmer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-24T21:48:47.000Z","updated_at":"2023-04-21T16:42:29.000Z","dependencies_parsed_at":"2022-06-26T23:32:18.051Z","dependency_job_id":null,"html_url":"https://github.com/blimmer/node-ember-cli-deploy-redis","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/blimmer/node-ember-cli-deploy-redis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fnode-ember-cli-deploy-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fnode-ember-cli-deploy-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fnode-ember-cli-deploy-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fnode-ember-cli-deploy-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blimmer","download_url":"https://codeload.github.com/blimmer/node-ember-cli-deploy-redis/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fnode-ember-cli-deploy-redis/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261338998,"owners_count":23143900,"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":"2024-10-11T10:15:34.411Z","updated_at":"2025-06-22T18:09:37.762Z","avatar_url":"https://github.com/blimmer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-ember-cli-deploy-redis [![Build Status](https://travis-ci.org/blimmer/node-ember-cli-deploy-redis.svg?branch=master)](https://travis-ci.org/blimmer/node-ember-cli-deploy-redis)\n\nExpressJS middleware to fetch the current (or specified) revision of your Ember App deployed by [ember-cli-deploy](https://github.com/ember-cli/ember-cli-deploy).\n\n## Why?\n\n[ember-cli-deploy](https://github.com/ember-cli/ember-cli-deploy) is great. It allows you to run\nmultiple versions in production at the same time and view revisions without impacting users.\nHowever, [the example provided](https://github.com/philipheinser/ember-lightning) uses [koa](http://koajs.com/)\nand many of us are not. This package allows you to easily fetch current and specified `index.html`\nrevisions from [redis](http://redis.io) with [Express](expressjs.com) and other Node servers.\n\n## Installation\n\nIt's important to choose the right version of this library to match the version of\nember-cli-deploy you're using.\n\n| ember-cli-deploy version | node-ember-cli-deploy-redis |\n|--------------------------|-----------------------------|\n| pre 0.5                  | ^0.2.0 or lower             |\n| 0.5 and beyond           | ^0.3.0 or newer             |\n\nMake sure to look at the\n[older documentation](https://github.com/blimmer/node-ember-cli-deploy-redis/blob/v0.2.0/README.md)\nif you're on a pre 0.5 ember-cli-deploy release.\nSee [the changelog](https://github.com/blimmer/node-ember-cli-deploy-redis/blob/develop/CHANGELOG.md#030---2015-11-07)\nfor an upgrade guide.\n\n## Usage\n\nThere are two main ways of using this library. For most simple Express servers, you'll\nwant to simply use the middleware. However, if you need more flexibility, you'll\nwant to use the internal `fetch` methods, with custom logic.\n\n### ExpressJS Middleware\n\n1. `require` the package\n2. `use` the package in your app\n\n#### Example\n\n```javascript\nconst express = require('express');\nconst app = express();\n\nconst nodeEmberCliDeployRedis = require('node-ember-cli-deploy-redis');\napp.use('/*', nodeEmberCliDeployRedis('myapp:index', {\n  host: 'redis.example.org',    // default is localhost\n  port: 6929,                   // default is 6379\n  password: 'passw0rd!',        // default is undefined\n  db: 0                         // default is undefined\n}));\n```\n\n\u003chr\u003e\n\n### Custom Fetch Method\n\n1. `require` the package\n2. Use the `fetchIndex` method\n3. Render the index string as you wish.\n\n#### Example\n\n```javascript\nconst express = require('express');\nconst app = express();\n\nconst fetchIndex = require('node-ember-cli-deploy-redis/fetch');\n\napp.get('/', function(req, res) {\n    fetchIndex(req, 'myapp:index', {\n      host: 'redis.example.org',\n      port: 6929,\n      password: 'passw0rd!',\n      db: 0\n    }).then(function (indexHtml) {\n    indexHtml = serverVarInjectHelper.injectServerVariables(indexHtml, req);\n    res.status(200).send(indexHtml);\n  }).catch(function(err) {\n    res.status(500).send('Oh noes!\\n' + err.message);\n  });\n});\n```\nCheck out [location-aware-ember-server](https://github.com/blimmer/location-aware-ember-server) for a running example.\n\n## Documentation\n\n### `nodeEmberCliDeployRedis(keyPrefix, connectionInfo, options)` (middleware constructor)\n\n* keyPrefix (required) - the application name, specified for ember deploy\n   the keys in redis are prefaced with this name. For instance, if your redis keys are `my-app:index:current`, you'd pass `my-app:index`.\n* connectionInfo (required) - the configuration to connect to redis.\n   internally, this library uses [ioredis](https://github.com/luin/ioredis), so pass a configuration supported by ioredis. please see their README for more information.\n* options (optional) - a hash of params to override [the defaults](https://github.com/blimmer/node-ember-cli-deploy-redis/blob/develop/README.md#options)\n\n### `fetchIndex(request, keyPrefix, connectionInfo, options)`\n\nArguments\n\n* request (required) - the request object\n   the request object is used to check for the presence of `revisionQueryParam`\n* keyPrefix (required) - the application name, specified for ember deploy\n   the keys in redis are prefaced with this name. For instance, if your redis keys are `my-app:index:current`, you'd pass `my-app:index`.\n* connectionInfo (required) - the configuration to connect to redis.\n   internally, this library uses [ioredis](https://github.com/luin/ioredis), so pass a configuration supported by ioredis.\n* options (optional) - a hash of params to override [the defaults](https://github.com/blimmer/node-ember-cli-deploy-redis/blob/develop/README.md#options)\n\nReturns\n\n* a `Promise`\n   when resolved, it returns the requested `index.html` string\n   when failed, it returns an [EmberCliDeployError](https://github.com/blimmer/node-ember-cli-deploy-redis/blob/develop/errors/ember-cli-deploy-error.js).\n\n### options\n\n* `revisionQueryParam` (defaults to `index_key`)\n   the query parameter to specify a revision (e.g. `http://example.org/?index_key=abc123`). the key will be automatically prefaced with your `keyPrefix` for security.\n* `memoize` (defaults to `false`)\n   enable memoizing Redis `get`s. see [the memoization section](#Memoization) for more details.\n* `memoizeOpts` ([see defaults](https://github.com/blimmer/node-ember-cli-deploy-redis/blob/master/fetch.js#L18))\n   customize memoization parameters. see [the memoization section](#Memoization) for more details.\n\n## Memoization\n\nSince the majority of the requests will be serving the `current` version of your\napp, you can enable memoization to reduce the load on Redis. By default, memoization\nis disabled. To enable it, simply pass:\n\n```javascript\nmemoize: true\n```\n\nin your options hash. Additionally, you can pass options to the underlying memoization\nlibrary ([memoizee](https://github.com/medikoo/memoizee)). Check out their documentation,\nand the [defaults](https://github.com/blimmer/node-ember-cli-deploy-redis/blob/master/fetch.js#L18)\nfor this library.\n\n### Example\n\n```javascript\napp.use('/*', nodeEmberCliDeployRedis(\n  'myapp:index',\n  { host: 'redis.example.org' },\n  { memoize: true },\n));\n```\n\n## Testing\n\nIn order to facilitate unit testing and/or integration testing this\nlibrary exports a mockable redis api.  You will need to use a\ndependency injection framework such as\n[rewire](https://github.com/jhnns/rewire) to activate this testing api.\n\n### Usage with rewire (mocha syntax)\n\n```javascript\n// my-module.js\nconst fetchIndex = require('node-ember-cli-deploy-redis/fetch');\nconst indexWrapper = function(req, res) {\n  return fetchIndex(req, 'app', {\n    // real redis config\n  }).then(function (indexHtml)) {\n    // do something with index\n  });\n};\nmodule.exports = indexWrapper;\n\n// my-module-test.js\nconst redisTestApi = require('node-ember-cli-deploy-redis/test/helpers/test-api');\nconst fetchIndex = rewire('node-ember-cli-deploy-redis/fetch');\nconst redis = redisTestApi.ioRedisApi;\nconst myModule = rewire('my-module');\n\ndescribe('my module', function() {\n  afterEach(function() {\n    fetchIndex.__set__('_initialized', false);\n  });\n\n  it('grabs my content', function() {\n    // inject mocked content\n    myModule.__set__('fetchIndex', fetchIndex);\n    fetchIndex.__set__('ioRedis', redis);\n    redis.set('app:abc123', \"\u003chtml\u003e\u003cbody\u003e\u003ch1\u003ehello test world\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e\");\n    myModule(req, res).then(function(){\n      // assertions here\n    })\n  });\n});\n```\n\n## Notes\n\n* Don't create any other redis keys you don't want exposed to the public under your `keyPrefix`.\n\n## Contributing\n\nComments/PRs/Issues are welcome!\n\n### Cloning\n\nThis project utilizes git submodules. Please use the following command to clone:\n\n```console\ngit clone --recurse-submodules https://github.com/blimmer/node-ember-cli-deploy-redis.git\n```\n\n### Running Project Unit Tests\n\n```console\nnpm test\n```\n\n### Running Project Smoke Tests\n\n```console\nnpm run smoke-test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblimmer%2Fnode-ember-cli-deploy-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblimmer%2Fnode-ember-cli-deploy-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblimmer%2Fnode-ember-cli-deploy-redis/lists"}