0

I have generated a simple angularJS project via AngularJS generator by yoeman

and after that created simple Spring-boot project with JPA repository which has one controller mehod with funcionality to select all users. The case is when I run both projects - spring on port 8080 and angular project on port 9000, there is no chance how the angular project can get to know about the data which spring is throwing.

My file tree in a project looks like:

enter image description here

And I think the problem is with index.html file. Normally it should be putted in a resource folder, so that spring project could communicate with angular project. But during grunt commend in cmd the build folder creates a new index.html file and the process makes circle. I thought about moving index.html file into resource folder but it doesn't make sense anymore.

I also thougt about changing the Gruntfile.js but honestly I don't know what excatly should I change. The Gruntfile looks like: Link to pastebin because the file was too long

Simple service:

angular.module('webappApp')
  .factory('myroute', function ($resource) {
    var service = $resource('/api/user', { id : '@id'},
      {


      });

    return service;
  });

Simple controller:

angular.module('webappApp')
  .controller('MyrouteCtrl', function (myroute) {
    console.log(myroute.query());
  });
9
  • what do you mean by "there is no chance how the angular project can get to know about the data which spring is throwing." ? You should be requesting through ajax request data to the java backend Commented Mar 14, 2017 at 22:20
  • I'm asking about them in js controller through $resource Commented Mar 14, 2017 at 22:23
  • ok, show us that code Commented Mar 14, 2017 at 22:23
  • Simple service: angular.module('webappApp') .factory('myroute', function ($resource) { var service = $resource('/api/user', { id : '@id'}, { }); return service; }); Simple controller: angular.module('webappApp') .controller('MyrouteCtrl', function (myroute) { console.log(myroute.query()); }); Commented Mar 14, 2017 at 22:24
  • update your question with that data Commented Mar 14, 2017 at 22:26

1 Answer 1

0

You need set in grunt proxy for endoints. For example grunt-connect-proxy

Add something like this:

grunt.initConfig({
    connect: {
        server: {
            options: {
                port: 8080,
                hostname: 'localhost'
            },
            proxies: [
                {
                    context: '/api',
                    host: 'localhost',
                    port: 8080,
                    https: false
                }
            ]
        }
    }
})

But this you need only for local development.

Sign up to request clarification or add additional context in comments.

6 Comments

Is it possbile to run spring project and angular both on port 8080? I don't think so it is possbile, so I can't imagine how it will be possible to work with?
At first example the index.html file is in resource. At my example it's diffrent - so I can't get that example as a help in my case :( At the second example I can't see any commons..
Or maybe the UI should be in a resources/static folder?
For example when I created a project via jhipster generator, it creates all "frontend" files in excatly the same path as above in a question
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.