Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

针对portal添加基于path的反向代理支持 #2754

Merged
merged 14 commits into from
Dec 1, 2019

Conversation

zjh-neverstop
Copy link
Contributor

@zjh-neverstop zjh-neverstop commented Nov 12, 2019

fixed 域名配置问题 #1154

@zjh-neverstop
Copy link
Contributor Author

在app.js中定义了path常量和filter,同时在AppUtil服务中定义了获取path的方法

var appUtil = angular.module('app.util', ['toastr', 'ngCookies', 'pascalprecht.translate'])
    .constant("prefixLocation", "这里为反向代理path")      // 前缀路径
    .filter('prefixPath',['prefixLocation', function(prefixLocation) {   // 前缀路径过滤器
        return function(text) {
            return prefixLocation + text;
        }
    }])

同时修改了js和html中对资源的引用路径,并进行了测试,可以支持基于path的反向代理

@codecov-io
Copy link

codecov-io commented Nov 12, 2019

Codecov Report

Merging #2754 into master will decrease coverage by 0.02%.
The diff coverage is 25%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2754      +/-   ##
============================================
- Coverage     50.48%   50.45%   -0.03%     
- Complexity     2084     2085       +1     
============================================
  Files           413      414       +1     
  Lines         12666    12668       +2     
  Branches       1294     1294              
============================================
- Hits           6394     6392       -2     
- Misses         5819     5822       +3     
- Partials        453      454       +1
Impacted Files Coverage Δ Complexity Δ
...lo/portal/spi/configuration/AuthConfiguration.java 5.84% <0%> (ø) 1 <0> (ø) ⬇️
...apollo/portal/controller/PrefixPathController.java 50% <50%> (ø) 1 <1> (?)
...mework/apollo/portal/component/PortalSettings.java 65.07% <0%> (-4.77%) 5% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe016be...c5d4b27. Read the comment docs.

@coveralls
Copy link

coveralls commented Nov 12, 2019

Coverage Status

Coverage decreased (-0.02%) to 54.042% when pulling c5d4b27 on zjh-neverstop:master into fe016be on ctripcorp:master.

@baiyun1102
Copy link
Contributor

这个功能挺不错的,希望能以配置参数的方式传入

@JaredTan95 JaredTan95 added enhancement area/ui Categorizes issue or PR as related to front end labels Nov 15, 2019
@nobodyiam
Copy link
Member

这个功能点很不错,👍

看代码,现在如果要配置反向代理路径的话,是需要修改app.js然后重新打包?
是否有可能做成配置参数,不需要重新打包?这样可能使用起来会更简便

@zjh-neverstop
Copy link
Contributor Author

这个功能点很不错,👍

看代码,现在如果要配置反向代理路径的话,是需要修改app.js然后重新打包?
是否有可能做成配置参数,不需要重新打包?这样可能使用起来会更简便

嗯,目前确实是需要修改app.js并重新打包,我抽空改一下

@zjh-neverstop
Copy link
Contributor Author

@nobodyiam
修改了一下,现在可通过application.properties来设置prefixPath的值,比如在config目录下添加一个application.properties文件,内容如下:

prefixPath=/apollo

然后重启一下portal即可生效,不用再打包了

@@ -271,7 +271,7 @@ protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.headers().frameOptions().sameOrigin();
http.authorizeRequests()
.antMatchers("/prometheus/**","/metrics/**","/openapi/**", "/vendor/**", "/styles/**", "/scripts/**", "/views/**", "/img/**", "/i18n/**").permitAll()
.antMatchers("/prometheus/**","/metrics/**","/openapi/**", "/vendor/**", "/styles/**", "/scripts/**", "/views/**", "/img/**", "/i18n/**", "/prefixPath").permitAll()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is another place to change, just search i18n in this program

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外一个地方已修改

@zjh-neverstop
Copy link
Contributor Author

@nobodyiam
code review中提到的两个问题已修改

@JaredTan95 JaredTan95 added this to the 1.6.0 milestone Nov 28, 2019
@RestController
public class PrefixPathController {

@Value("${prefixPath: }") private String prefixPath;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Value("${prefixPath: }") will cause the default prefixPath to be " " instead of "".
Though it is still working(I guess the browser does some trick), I would suggest we change it as follows:

@Value("${prefixPath:}")
private String prefixPath;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, it works as expected. And a FAQ is added for this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按照建议进行修改

@WilliamThh
Copy link

@nobodyiam 我拉下最新的代码,编译并且使用-DprefixPath=/apollo -Dserver.servlet.context-path=/apollo,可以访问,但是出现了以下两个问题

  1. 输入用户名密码点击登录会报以下错误:{"exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method \u0027POST\u0027 not supported","status":400,"timestamp":"2019-12-09T19:38:17.267"}

2.在控制面板点击用户再点退出,会自动跳到根路径,报404

@WilliamThh
Copy link

问题解决,启动时添加-Dapollo_profile=github,auth -DprefixPath=/apollo -Dserver.servlet.context-path=/apollo参数

我是用Idea编译的,-Dapollo_profile=github,auth必须添加,否则会出现#2142 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.这样的报错

@gy09535
Copy link
Contributor

gy09535 commented Mar 9, 2022

问题解决,启动时添加-Dapollo_profile=github,auth -DprefixPath=/apollo -Dserver.servlet.context-path=/apollo参数

我是用Idea编译的,-Dapollo_profile=github,auth必须添加,否则会出现#2142 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.这样的报错

use -Dprefix.path=/apollo -Dserver.servlet.context-path=/apollo can work

ref: https://github.com/apolloconfig/apollo/blob/master/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PrefixPathController.java#L32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ui Categorizes issue or PR as related to front end enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants