[英]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')
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.