npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-cli-server-variables

v3.0.0

Published

Insert meta tag server variables into ember-cli built Ember applications.

Downloads

9,766

Readme

ember-cli-server-variables Build Status Ember Observer Score Code Climate

An Ember CLI add-on to support adding variables to the generated index.html file's head tag.

<html>
  <head>
    <meta name='your-app-token' content='example:app:token'>
    <meta name='your-app-user-location' content='Denver'>
    <meta name='your-app-json-data' content='{"foo":"bar"}'>
  </head>
</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.

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

Usage

You need to install and configure this add-on for it to work properly.

Installation

In your CLI project, run

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.
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:

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:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Dummy</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {{content-for 'head'}}

    <link rel="stylesheet" href="assets/vendor.css">
    <link rel="stylesheet" href="assets/dummy.css">

    <!-- THIS IS THE IMPORTANT BIT! -->
    {{content-for 'server-variables'}}
    <!-------------------------------->

    {{content-for 'head-footer'}}
  </head>
  <body>
    {{content-for 'body'}}

    <script src="assets/vendor.js"></script>
    <script src="assets/dummy.js"></script>

    {{content-for 'body-footer'}}
  </body>
</html>

Ensure you've defined a vars array in your config/environment.js file

Make sure that you followed the configuration instructions to get your vars defined.

Development

Installation

  • git clone this repository
  • npm install

Running

  • ember server
  • Visit your app at http://localhost:4200.

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

See the Contributing guide for details. For more information on using ember-cli, visit http://www.ember-cli.com/.