0

although I'm able to serve from filesystem the grunt-ngdocs automatically generated index.html, everytime I try to look to a description in the documentation I'm getting:

XMLHttpRequest cannot load file:///C:/<file-path> Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource

even if both the docs/partials and docs/partials/api folders are empty.

This is my grunt-ngdocs configuration

ngdocs: {
       options: {
           dest: 'docs',
           html5Mode: false,
           inlinePartials: true,
           scripts: [
               'bower_components/angular/angular.js',
               'bower_components/angular-animate/angular-animate.js'
           ]
       },
       api: {
           src: ['app/scripts/**/*.js'],
           title: 'Docs'
       }
    }

What am I doing wrong?

Thank you in advance

Gargaroz
  • 313
  • 9
  • 28

1 Answers1

-1

Problem is you have to run it from a server. I use a node http server (https://www.npmjs.com/package/http-server). After installing it, just head into the docs/ directory and type 'http-server'. You will get the following message:

Starting up http-server, serving ./ on: http://0.0.0.0:8080

You can now check the docs on the given URL (http://0.0.0.0:8080)

Edit:

If you don't want to load it from a server, you can set the option inlinePartials to true in the gruntfile. This is what I have:

ngdocs: {
    options: {
        dest: 'docs', 
        title: "Docs",
        inlinePartials: true
    },
    api: {
      src: ['<%= yeoman.app %>/scripts/**/*.js'],
      title: 'API Documentation'
    }
},

see (https://github.com/m7r/grunt-ngdocs)

  • Thank you for your answer, but the fact is I was trying to avoid that solution since one of the contributor said [ng-docs could be served via file system](https://github.com/m7r/grunt-ngdocs/issues/148#issuecomment-110430549); moreover, I found in a question kinda related to mine about [`grunt serve:dist`](http://stackoverflow.com/a/21285745/4277702): can you tell me if would it be possible to serve the ngdocs using that Grunt task? – Gargaroz Aug 03 '16 at 08:04
  • I've checked if there is another way, and ngdocs does allow you to make all templates inline. This will avoid the XMLHttpRequest error. Check the edited answer. – andreboekhorst Aug 03 '16 at 21:53
  • My problem is I **DO** have `inlinePartials: true` in my Gruntfile, but I'm still getting XMLHttpRequest errors – Gargaroz Aug 04 '16 at 07:40
  • Do you know which version of ngdocs you have? Inline partials are only allowed since 0.2.8 (maybe you can check package.json) – andreboekhorst Aug 04 '16 at 07:54
  • btw I added http-server to my npm packages, but I still can't see anything: the index page of the ngdocs is correctly loaded, but when comes to select an element from the left nav to see its docs, I get in console 404 for its partial – Gargaroz Aug 04 '16 at 09:54
  • Finally I removed `inlinePartials: true` and served the docs through http-server and everything it's fine. I'm still disappointed I could not find a way to make it work through `inlinePartials: true` – Gargaroz Aug 04 '16 at 13:24