Skip to content

Commit

Permalink
fix: use proxy.conf.js instead of proxy.conf.json (#2125)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Nov 7, 2021
1 parent e3c3a09 commit 2d87d55
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion angular.json
Expand Up @@ -67,7 +67,7 @@
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "ng-alain:build",
"proxyConfig": "proxy.conf.json"
"proxyConfig": "proxy.conf.js"
},
"configurations": {
"production": {
Expand Down
17 changes: 17 additions & 0 deletions proxy.conf.js
@@ -0,0 +1,17 @@
/**
* For more configuration, please refer to https://angular.io/guide/build#proxying-to-a-backend-server
*
* 更多配置描述请参考 https://angular.cn/guide/build#proxying-to-a-backend-server
*
* Note: The proxy is only valid for real requests, Mock does not actually generate requests, so the priority of Mock will be higher than the proxy
*/
module.exports = {
/**
* The following means that all requests are directed to the backend `https://localhost:9000/`
*/
// '/': {
// target: 'https://localhost:9000/',
// secure: false, // Ignore invalid SSL certificates
// changeOrigin: true
// }
};
2 changes: 0 additions & 2 deletions proxy.conf.json

This file was deleted.

3 changes: 2 additions & 1 deletion src/app/core/net/default.interceptor.ts
Expand Up @@ -241,7 +241,8 @@ export class DefaultInterceptor implements HttpInterceptor {
// 统一加上服务端前缀
let url = req.url;
if (!url.startsWith('https://') && !url.startsWith('http://')) {
url = environment.api.baseUrl + url;
const { baseUrl } = environment.api;
url = baseUrl + (baseUrl.endsWith('/') && url.startsWith('/') ? url.substring(1) : url);
}

const newReq = req.clone({ url, setHeaders: this.getAdditionalHeaders(req.headers) });
Expand Down

0 comments on commit 2d87d55

Please sign in to comment.