0
votes

In my production environment the Angular app is served under the same domain as the API therefore the base url is in the form of e.g. '/api'.

The problem is when I develop I'm using grunt serve (grunt-contrib-connect) as my development server and I would like to specify a base url for the API Endpoint when I start it e.g. grunt serve --endpoint="http://localhost/api"

I know I can get this value using grunt.option however, I don't know how to pass this along to my Angular App.

Note: this is not your typical production/development config split. I want the endpoint to be specified every time the development server is started.

Any solutions? The simpler the better!

1

1 Answers

0
votes

This is what you want: https://github.com/jsoverson/grunt-env

In your Gruntfile.js you'll specify and ENV variable:

grunt.initConfig({
  env: {
    development: {
      ENV: 'development'
    },

    production: {
      ENV: 'production'
    }
  },

  // ...

And somewhere in your client code, like in my settings.js file you'll do something like this:

// @if ENV='development'
'api_base_url': 'http://localhost:' + (apiPort || 4000),
'base_url': 'http://localhost:7777',
'env': 'development'
// @endif