简体   繁体   English

Angular 通用快递服务器显示 function url 而不是条目 url

[英]Angular universal express server shows function url instead of entry url

Help i need to get my custom domain to fetch store config but when I try to use the url on the server side is showing me the cloud function url, not the url that the user typed in. example: my user types in the browser https://test-url.mybuss.co/ Hosting redirects to functions (ie https://us-east1-blablabla.com/ ) functions renders my html this includes making some http calls to my API BUT I have two ways to recognize which company is trying to check my store帮助我需要让我的自定义域获取商店配置,但是当我尝试在服务器端使用 url 时,我看到的是云 function url,而不是用户输入的 url。示例:我的用户在浏览器中输入 https ://test-url.mybuss.co/托管重定向到函数(即https://us-east1-blablabla.com/ )函数呈现我的 html 这包括对我的 API 进行一些 http 调用但我有两种方法可以识别哪家公司试图检查我的商店

First one query params https://test-url.mybuss.co/myStore I sent myStore as a query parameter and success second case https://test-url.mybuss.co/ I sent the host url as a parameter and success BUT whenever I'm on server side instead of sending this URL( https://test-url.mybuss.co/ ) the express server catches the cloud function url. Any ideas?第一个查询参数https://test-url.mybuss.co/myStore我发送 myStore 作为查询参数并成功第二种情况https://test-url.mybuss.co/我发送主机 url 作为参数并成功但是每当我在服务器端而不是发送此 URL( https://test-url.mybuss.co/ )时,快速服务器就会捕获云 function url。有什么想法吗?

I've tried every host parameter我已经尝试了每个主机参数

console.log(req.headers.host);

console.log(req.hostname);

console.log(req.host); // even this deprecated one

console.log(req.subdomains)

and they all give me the same result https://us-east1-blablabla.com/他们都给我相同的结果https://us-east1-blablabla.com/

Tried using platformLocation and also tried this solution right here尝试使用 platformLocation 并在此处尝试了此解决方案

req.get('host')

get server url 获取服务器 url

So the solution to my answer was using the parameter x-fowarded-Host Which I obtained by req.get('x-forwarded-Host') And transfered through providers所以我的答案的解决方案是使用参数 x-fowarded-Host 我通过 req.get('x-forwarded-Host') 获得并通过提供者传输

 res.render(indexHtml, {
      req, providers: [
        { provide: APP_BASE_HREF, useValue: req.baseUrl },
        { provide: 'ORIGIN_URL', useValue: req.get('x-forwarded-Host') },
      ]
    });

I also had to include these lines app.server.module.ts我还必须包括这些行 app.server.module.ts

@NgModule({
  imports: [
    AppModule,
    ServerModule,
    ServerTransferStateModule,
  ],

app.module.ts应用程序模块.ts

  imports: [
    BrowserTransferStateModule
],

to retrieve the data in my resolver I had to include this variable in my constructor为了在我的解析器中检索数据,我必须在我的构造函数中包含这个变量

@Optional() @Inject('ORIGIN_URL') public urlOrigin: string

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

相关问题 GET url 在 Angular/Typescript 中导致未知错误而不是成功 - GET url in Angular/Typescript results in Unknown Error instead of success 键入 URL 每次都显示 404 - Type URL shows 404 everytime 从 Firestore URL 获取显示 404 - URL 不对吗? - Fetching from Firestore URL shows 404 - URL not right? Angular 通用显示注释而不是动态组件数据 - Angular Universal displays comments instead of dynamic component data 使用 Cloud Function 将图片 URL 上传到 SFTP 服务器 - Upload image URL to SFTP server using Cloud Function 在 Angular 和 rxjs 中获取 FireStorage URL 直到渲染 - get FireStorage URL in Angular with rxjs until rendering Flask redirect url_for 生成 Cloud Run 服务 URL 而不是域 - Flask redirect url_for generates Cloud Run service URL instead of domain 在 Node JS 中使用 url 链接而不是文件路径 - Use url link instead of path to file in Node JS Azure 广告登录重定向 url 是 http 而不是 https - Azure Ad login redirect url is http instead of https C# Azure Function 在 URL 中对 '/' 进行切片 - C# Azure Function is slicing '/' in URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM