[英]Angular 7 Cookie for SSR (universal)
I'm trying to implement SSR for my angular app.我正在尝试为我的 angular 应用程序实现 SSR。 I followed the universal starter guide ( https://angular.io/guide/universal ).
我遵循了通用入门指南( https://angular.io/guide/universal )。
My angular app consumes a rest API which need an access_token (client_credentials grant_type) for all requests.我的 angular 应用程序使用 rest API ,所有请求都需要 access_token (client_credentials grant_type)。 Im using cookies to store it on the client side.
我使用 cookies 将其存储在客户端。
I know that cookies can't work from scratch on the server side.我知道 cookies 不能在服务器端从头开始工作。 So i tried some packages (ngx-cookie-service) but i can't find one for SSR and angular 7...
所以我尝试了一些包(ngx-cookie-service),但我找不到 SSR和angular 7 的包...
Lately i found this package (ngx-auth) but i'm not sure i can use it for that purpose...最近我发现了这个 package (ngx-auth) 但我不确定我是否可以将它用于此目的......
I can't find any documentation on the universal website, if someone have successfully implemented cookies for universal using angular 7...如果有人使用 angular 7 成功实现了通用的 cookies,我在通用网站上找不到任何文档...
A big thanks !非常感谢!
Ok i finally succeed using @gorniv/ngx-universal , following https://github.com/Angular-RU/angular-universal-starter好的,我终于成功使用@gorniv/ngx-universal ,遵循https://github.com/Angular-RU/angular-universal-starter
If needed i can provide an implementation example with angular 9.如果需要,我可以提供一个角度为 9 的实现示例。
here's my solution :
getssrCockie(){
if (this.req !== null) {
const cookies = new Cookies(this.req.headers.cookie);
const clubInfo = cookies.get('clubInfo')
return clubInfo
} else {
const cookies = new Cookies();
const clubInfo2 = cookies.get('clubInfo')
return clubInfo2
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.