繁体   English   中英

如何为jhipster网关应用程序定义SERVER_API_URL?

[英]How to define a SERVER_API_URL to a jhipster gateway application?

我有一个没有后端结构的jhipster网关应用程序。 它是使用--skip-server选项创建的 当我使用Commando GULP运行网关应用程序时,定义的端口为8080,但jhipster API应用程序位于8081上。 如何定义此默认网址?

我更改了文件:

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' };

但这没有用。 我能做什么?

没有为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_URLngconstant:devngconstant: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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM