https://github.com/blimmer/ember-cli-server-variables
Insert meta tag server variables into ember-cli built Ember applications
https://github.com/blimmer/ember-cli-server-variables
Last synced: about 2 months ago
JSON representation
Insert meta tag server variables into ember-cli built Ember applications
- Host: GitHub
- URL: https://github.com/blimmer/ember-cli-server-variables
- Owner: blimmer
- License: mit
- Created: 2015-03-28T20:47:01.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2022-12-08T18:18:20.000Z (over 2 years ago)
- Last Synced: 2024-05-21T11:03:13.112Z (12 months ago)
- Language: JavaScript
- Size: 2.98 MB
- Stars: 31
- Watchers: 4
- Forks: 5
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-ember - ember-cli-server-variables - An Ember CLI add-on to support adding variables to the generated index.html file's head tag. (Packages / CI/CD)
README
# ember-cli-server-variables [](https://travis-ci.org/blimmer/ember-cli-server-variables) [](http://emberobserver.com/addons/ember-cli-server-variables) [](https://codeclimate.com/github/blimmer/ember-cli-server-variables)
An [Ember CLI](http://www.ember-cli.com/) add-on to support adding variables
to the generated index.html file's `head` tag.```html
```
This is handy when you need to dynamically insert variables from your application
server, such as a session application token to communicate with your API or a user's
location based on their request IP address.You can modify the blank `content` tags on your generated index.html file using
a library like [Cheerio](https://github.com/cheeriojs/cheerio).## Compatibility
- Ember.js v4.12 or above
- Ember CLI v4.12 or above
- Node.js v18 or above## Usage
You need to install and configure this add-on for it to work properly.### Installation
```
ember install ember-cli-server-variables
```### Configuration
Add a `serverVariables` block your `environment.js` file.Configuration Variables:
* vars (**required**): An array of your server variables. Convention is to use dasherized names.
* tagPrefix: a prefix to append to every meta tag to avoid collision. Defaults to `ENV.modulePrefix`.
* defaults: a POJO of default values for your server variables. **Note:** If
you don't provide defaults, the fallback is a blank string. Most of the time
you'll probably want to only provide defaults in development mode.```javascript
module.exports = function(environment) {
var ENV = {
serverVariables: {
tagPrefix: 'your-app',
vars: ['app-token', 'user-location', 'key']
}
};...
if (environment === 'development') {
ENV.serverVariables.defaults = {
'app-token': 'dev-app-token',
'user-location': 'Denver'
};
}
};
```### Usage
This plugin provides a service to retrieve the server variables in your
Ember app. You can use it like this:```javascript
export default Ember.Component.extend({
serverVariablesService: Ember.inject.service('serverVariables'),userLocation: Ember.computed.reads('serverVariablesService.userLocation')
});
```## Troubleshooting
Some tips & tricks if something isn't working correctly.### Check that the `{{content-for 'server-variables'}}` tag is present in your `app/index.html` file
This is how we insert the meta tags into your app. We try to do this automatically
when you `ember install` this addon, but there are potentially times where this
operation could fail. Your `app/index.html` file should look something like this:```html
Dummy
{{content-for 'head'}}
{{content-for 'server-variables'}}
{{content-for 'head-footer'}}
{{content-for 'body'}}
{{content-for 'body-footer'}}
```
### Ensure you've defined a `vars` array in your `config/environment.js` file
Make sure that you followed the [configuration instructions](#configuration)
to get your vars defined.## Contributing
See the [Contributing](CONTRIBUTING.md) guide for details.## License
This project is licensed under the [MIT License](LICENSE.md).