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