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

问题描述 投票:0回答:1

我有一个没有后端结构的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' };

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

javascript java gulp jhipster gateway
1个回答
0
投票

没有为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:prodgulpfile.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

© www.soinside.com 2019 - 2024. All rights reserved.