Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ssr): adds server cookie output via response #320

Open
wants to merge 8 commits into
base: development
Choose a base branch
from

Conversation

blakeoxx
Copy link

@blakeoxx blakeoxx commented Aug 11, 2024

This brings the fix/feature completed in #315 to the v18 codebase and resolves #266 . It increases the SsrCookieServices ability to use the request and response objects provided by Express to read and write cookies on the server side. This also means that cookies written during SSR will be returned to the client in the response headers.

This PR also includes less refactors than the previous one, per maintainer request. The only refactors included in this PR were strictly necessary for enabling this feature.

From #309
This fix/feature resolves #266 . It increases the SsrCookieServices ability to use the request and response objects provided by Express to read and write cookies on the server side. This also means that cookies written during SSR will be returned to the client in the response headers.

Partitioned cookies aren't supported by express yet due to a dependency on an older version of the cookie package. See expressjs/express#5275. Adding an override for a higher version of the cookie package which does support partitioned cookies fixes this.
Deletion uses the cookie setter with a past date in the expiration options. Now that the setter is updated to support server cookies as well, this will work for both client and server cookies.
Copy link

sonarcloud bot commented Aug 11, 2024

@abinvp
Copy link

abinvp commented Sep 2, 2024

When is this going to be merged? Seems like this is capable of solving some significant challenges.

@pavankjadda
Copy link
Collaborator

@blakeoxx I tried this and didn't work as expected. For example, setting cookie in SsrCookieServices using the code does not set it. Do you have an example where it shows this code working?

@blakeoxx
Copy link
Author

blakeoxx commented Sep 8, 2024

@pavankjadda try out this test repo: https://github.com/blakeoxx/ngx-cookie-service-18-test. You can build and start the project with npm run build followed by npm run serve:ssr:ssr-cookie-test.

I generated this project with Angular's ng new --ssr command, added the scaffolding to server.ts as outlined in our README, and added a test to the AppComponent which outputs console logs on the server console and client/browser console to confirm the server-side cookie is readable and writable by both platforms. Example output.

Additionally, something I noticed was that NG18's SSR defaults to using prerendering. I had to disable this in the builder architect configuration. It's intended behavior that SSR won't run on prerendered routes and not a bug of this code, but perhaps may be worth calling out in the README.

Let me know if you need anything else or don't see expected results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants