我有一个没有后端结构的jhipster网关应用程序。它是使用--skip-server选项创建的。当我使用命令GULP运行网关应用程序时,定义的端口是8080但是jhipster API应用程序在8081上。如何定义这个默认网址?
我在文件中更改了:
一饮而尽/ 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' };
但它没有用。我能做什么?
没有为AngularJS项目预先配置的SERVER_API_URL
变量。它默认只出现在Angular(v4 +)JHipster项目中。因此,所有AngularJS服务都会根据它们所在的相对路径(通常是端口8080或9000)向API发送请求。然后,gulp
代理从端口9000到gulp/config.js
中定义的API端口的任何请求。
要在整个项目中自定义SERVER_API_URL
,可以将配置变量添加到app.constants.js
。为此,将SERVER_API_URL
添加到ngconstant:dev
中的ngconstant:prod
和gulpfile.js
部分。运行gulp
会将变量注入app.constants.js
。
一旦变量出现在app.constants.js
中,您就可以将它注入到使用AngularJS的$resource
或$http
的服务JS文件中。例如在account.service.js
中,你应该注入SERVER_API_URL
并将URL从'api/account'
更改为SERVER_API_URL + 'api/account'
。
您可以通过IDE或使用像grep这样的工具查看使用AngularJS的$resource
和$http
的完整文件列表:grep -R '$resource\|$http' ./src/main/webapp/app