Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple spaces: requests are missing the host #29

Closed
wrmz opened this issue Jan 12, 2018 · 1 comment
Closed

Multiple spaces: requests are missing the host #29

wrmz opened this issue Jan 12, 2018 · 1 comment

Comments

@wrmz
Copy link

wrmz commented Jan 12, 2018

I may be doing something incorrectly here, so I apologize for my ignorance if that's the case.

I have a contentful.config.js file that has the following so that I can reference multiple spaces:

function ContentfulConfig(contentfulProvider) {
    contentfulProvider.setOptions({
        'default': {
            space: `${space_id}`,
            accessToken: `${access_token}`
        },
        'another': {
            space: `${space_id}`,
            accessToken: `${access_token}`
        }
    });
}
ContentfulConfig.$inject = ['contentfulProvider'];
export default ContentfulConfig;

In my app.routes.js I have the following (using ui-router):

function appRoutes($stateProvider) {
    $stateProvider
        ...
        .state('app.cli', {
            url: '/cli',
            template: cliTemplate,
            controller: 'CLIController as cli',
            resolve: {
                contents: ['contentful', (contentful) => {
                    return contentful
                        .entries('', 'jscli')
                        .then((response) => {
                            return response.data;
                        }, (error) => {
                            console.log(`Error: ${response.status}`);
                        });
                }]
            }
        });
}
appRoutes.$inject = ['$stateProvider'];
export default appRoutes;

When navigating to this page, so that a call is made to the API for the requested data, I was getting a malformed URI error.

Delving in I found that the request was going to http://:80/spaces/${space_id}/entries.

It was missing the host.

Ensuring that the host is supplied among the options in contentful.config.js for each space resolved the issue.

I'm assuming that this might be as easy as adding this instruction to the documentation examples, but I didn't dig deep enough to learn why the host wasn't remaining intact when merged on line 313 of angular-contentful.js in this.setOptions() method.

Edit: grammar.

@jvandemo
Copy link
Owner

jvandemo commented Apr 9, 2018

@wrmz — we have updated the documentation to be more explicit:

angular
  .module('yourApp')
  .config(function(contentfulProvider){
    contentfulProvider.setOptions({
        'default': {
          host: 'cdn.contentful.com',
          space: 'first_space',
          accessToken: 'first_token'
        },
        'another': {
          host: 'cdn.contentful.com',
          space: 'second_space',
          accessToken: 'second_token'
        }
        ...
    });
  });

Thank you for your feedback, much appreciated! 👍

@jvandemo jvandemo closed this as completed Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants