我知道这个问题已经以多种不同的形式被提出。但我已经阅读了我能找到的关于此事的所有帖子和文章,但无法根据我们面临的先决条件解决我的问题。因此,我想首先描述我们的问题并给出我们的动机,然后描述我们已经尝试过或正在使用的不同方法,尽管它们并不令人满意。
我们的设置可以说是有些复杂。我们的 Angular 应用程序部署在多个 Kubernetes 集群上,并通过不同的路径提供服务。
集群本身位于代理后面,并且 Kubernetes 本身添加了一个名为 Ingress 的代理。因此,我们的常见设置可能如下所示:
当地的
http://本地主机:4200/
本地集群
https://kubernetes.local/angular-app
发展
https://ourcompany.com/proxy-dev/kubernetes/angular-app
分期
https://ourcompany.com/proxy-staging/kubernetes/angular-app
顾客
https://kubernetes.customer.com/angular-app
应用程序始终以不同的基本路径提供服务。由于这是 Kubernetes,我们的应用程序是使用 Docker 容器部署的。
通常,人们会使用ng build
转译 Angular 应用程序,然后使用如下所示的 Dockerfile:
FROM nginx:1.17.10-alpine
EXPOSE 80
COPY conf/nginx.conf /etc/nginx/conf.d/default.conf
RUN rm -rf /usr/share/nginx/html/*
COPY dist/ /usr/share/nginx/html/
Run Code Online (Sandbox Code Playgroud)
要告诉 CLI 如何设置 base-href 以及从何处提供资源,可以使用Angular CLI 的--base-href
和选项。--deploy-url
不幸的是,这意味着我们需要为每个要部署应用程序的环境构建一个 Docker 容器。
此外,我们必须注意在这个预构建过程中设置其他环境变量,例如在environments[.prod].ts
每个部署环境中。
我们当前的解决方案包括在部署期间构建应用程序。这是通过使用另一个 Docker 容器作为所谓的initContainer来实现的,该容器在 nginx 容器启动之前运行。
该 Dockerfile 如下所示:
FROM node:13.10.1-alpine
# set working …
Run Code Online (Sandbox Code Playgroud) 我试图通过函数获取文档的基本路径,因为我不想找到像../folder1/folder2/mypage.php
或的路径../../../folder1/folder2/somepage.php
.
所以我试过......
function getBaseUrl() {
// output: /myproject/index.php
$currentPath = $_SERVER['PHP_SELF'];
// output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index )
$pathInfo = pathinfo($currentPath);
// output: localhost
$hostName = $_SERVER['HTTP_HOST'];
// output: http://
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://'?'https://':'http://';
// return: http://localhost/myproject/
return $protocol.$hostName.$pathInfo['dirname']."/";
}
Run Code Online (Sandbox Code Playgroud)
然后我给写代码......
$base = getBaseUrl();
require_once $base.'_include/db/qry.php';
require_once $base.'_include/db/functions.php';
Run Code Online (Sandbox Code Playgroud)
这两个文件qry.php
和functions.php
在http://localhost/mysite/_include/db/
当我运行页面时,错误显示...
Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 …
Run Code Online (Sandbox Code Playgroud) 每当我重新启动我的应用程序时,它的finder中的文件夹名称就会改变
09323D3F-D371-4556-ABA3-BD23AF487F12
至
E771BBEC-ACC6-489C-B7C1-B5FF11004CB2 /
NSHomeDirectory()
每次我在模拟器中运行应用程序时都在改变.