I have a jhipster gateway application that has no back-end structure. It was created with --skip-server option. When I run the gateway application with the commando GULP the port defined is 8080 but The jhipster API application is on 8081 . How to define this default url?
I changed in the file:
gulp/config.js
'use strict';
module.exports = {
app: 'src/main/webapp/',
dist: 'build/www/',
swaggerDist: 'build/www/swagger-ui/',
test: 'src/test/javascript/',
bower: 'src/main/webapp/bower_components/',
tmp: 'build/tmp',
revManifest: 'build/tmp/rev-manifest.json',
port: 8080,
apiPort: 8081,
liveReloadPort: 35729,
uri: 'http://localhost:',
constantTemplate:
'(function () {\n' +
' \'use strict\';\n' +
' // DO NOT EDIT THIS FILE, EDIT THE GULP TASK NGCONSTANT SETTINGS INSTEAD WHICH GENERATES THIS FILE\n' +
' angular\n' +
' .module(\'<%- moduleName %>\')\n' +
'<% constants.forEach(function(constant) { %> .constant(\'<%- constant.name %>\', <%= constant.value %>)\n<% }) %>;\n' +
'})();\n' };
But it did not work. What can I do?
There is no SERVER_API_URL
variable pre-configured for AngularJS projects. It is only present in Angular (v4+) JHipster projects by default. Because of this, all AngularJS services send requests to the API based on a relative path to where they are hosted (usually port 8080 or 9000). gulp
then proxies any requests from port 9000 to the API port defined in gulp/config.js
.
To customize the SERVER_API_URL
throughout the project, you can add a config variable to app.constants.js
. To do this, add a SERVER_API_URL
to the ngconstant:dev
and ngconstant:prod
sections in your gulpfile.js
. Running gulp
will inject the variable into app.constants.js
.
Once the variable is present in app.constants.js
, you can inject it into your service JS files that use AngularJS's $resource
or $http
. For example in account.service.js
, you should inject SERVER_API_URL
and change the URL from just 'api/account'
to SERVER_API_URL + 'api/account'
.
You can see a full list of files that use AngularJS's $resource
and $http
by searching with your IDE or using a tool like grep: grep -R '$resource\|$http' ./src/main/webapp/app