Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ Only install `ngx-cookie-service-ssr` library (and skip `ngx-cookie-service`) fo
with this

```typescript
import { REQUEST } from '@angular/core';

server.get('*', (req, res) => {
res.render(indexHtml, {
req,
providers: [
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
{ provide: 'REQUEST', useValue: req },
{ provide: 'RESPONSE', useValue: res },
{ provide: REQUEST, useValue: req }
],
});
});
Expand Down Expand Up @@ -284,6 +285,7 @@ Thanks to all contributors:
- [IceBreakerG](https://github.com/IceBreakerG)
- [rojedalopez](https://github.com/rojedalopez)
- [Nikel163](https://github.com/Nikel163)
- [Martin Evtimov](https://github.com/mmart1n)

# License

Expand Down
6 changes: 4 additions & 2 deletions projects/ngx-cookie-service-ssr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ Only install `ngx-cookie-service-ssr` library (and skip `ngx-cookie-service`) fo
with this

```typescript
import { REQUEST } from '@angular/core';

server.get('*', (req, res) => {
res.render(indexHtml, {
req,
providers: [
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
{ provide: 'REQUEST', useValue: req },
{ provide: 'RESPONSE', useValue: res },
{ provide: REQUEST, useValue: req }
],
});
});
Expand Down Expand Up @@ -317,6 +318,7 @@ Thanks to all contributors:
- [IceBreakerG](https://github.com/IceBreakerG)
- [rojedalopez](https://github.com/rojedalopez)
- [Nikel163](https://github.com/Nikel163)
- [Martin Evtimov](https://github.com/mmart1n)

# License

Expand Down
3 changes: 3 additions & 0 deletions projects/ngx-cookie-service-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
},
{
"name": "IceBreakerG"
},
{
"name": "Martin Evtimov"
}
],
"repository": {
Expand Down
14 changes: 11 additions & 3 deletions projects/ngx-cookie-service-ssr/src/lib/ssr-cookie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export class SsrCookieService {
check(name: string): boolean {
name = encodeURIComponent(name);
const regExp: RegExp = SsrCookieService.getCookieRegExp(name);
return regExp.test(this.documentIsAccessible ? this.document.cookie : this.request?.headers.get('cookie'));
return regExp.test(this.documentIsAccessible ?
this.document.cookie :
(this.request?.headers.cookie ?? this.request?.headers.get('cookie'))
);
}

/**
Expand All @@ -72,7 +75,10 @@ export class SsrCookieService {
if (this.check(name)) {
name = encodeURIComponent(name);
const regExp: RegExp = SsrCookieService.getCookieRegExp(name);
const result = regExp.exec(this.documentIsAccessible ? this.document.cookie : this.request?.headers.get('cookie'));
const result = regExp.exec(this.documentIsAccessible ?
this.document.cookie :
(this.request?.headers.cookie ?? this.request?.headers.get('cookie'))
);
return result && result[1] ? SsrCookieService.safeDecodeURIComponent(result[1]) : '';
}
return '';
Expand All @@ -88,7 +94,9 @@ export class SsrCookieService {
*/
getAll(): { [key: string]: string } {
const cookies: { [key: string]: string } = {};
const cookieString: any = this.documentIsAccessible ? this.document?.cookie : this.request?.headers.get('cookie');
const cookieString: any = this.documentIsAccessible ?
this.document?.cookie :
(this.request?.headers.cookie ?? this.request?.headers.get('cookie'));

if (cookieString && cookieString !== '') {
cookieString.split(';').forEach((currentCookie: string) => {
Expand Down
6 changes: 4 additions & 2 deletions projects/ngx-cookie-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ Only install `ngx-cookie-service-ssr` library (and skip `ngx-cookie-service`) fo
with this

```typescript
import { REQUEST } from '@angular/core';

server.get('*', (req, res) => {
res.render(indexHtml, {
req,
providers: [
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
{ provide: 'REQUEST', useValue: req },
{ provide: 'RESPONSE', useValue: res },
{ provide: REQUEST, useValue: req }
],
});
});
Expand Down Expand Up @@ -317,6 +318,7 @@ Thanks to all contributors:
- [IceBreakerG](https://github.com/IceBreakerG)
- [rojedalopez](https://github.com/rojedalopez)
- [Nikel163](https://github.com/Nikel163)
- [Martin Evtimov](https://github.com/mmart1n)

# License

Expand Down