-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Universal Support #1
Comments
Hey there :) We did not plan on doing that. However, if you have some experience with this and would like to submit a pull request, we’d be very happy to accept it. If you need that functionality right now, check out the ngx-cookie package. It already has a backend service. Cheers from Berlin |
Ok what a pity. But I will have a look into it. The question is have can I easily extend your cookieService. I see no way in doing something like:
so that I can use the DI of Angular to provide MyBackendService on the server-side and CookieService on the client-side like e.g.
Cheers from Austria |
Currently the service has a strong dependency on document.cookie. As I see it an universal cookie service would have to abstract from it and use getter/setter for the cookie-string and instead work with the request object on the backend. That would require some refactoring and just extending the service as it is would not be feasible |
We got the idea about the ngx-cookie package’s support from this file: ngx-cookie/src/cookie-backend.service.ts. We didn’t actually test it, though... |
export * from './cookie-service/cookie.service'; SyntaxError: Unexpected token export |
Hello everyone, we are currently working with Vue and not with Angular. This will not affect this package's support, of course. However, I have no experience with Universal and that will probably not change in the foreseeable future. I am going to mark this as Cheers |
Just for the record. I deleted two comments that have absolutely nothing to do with this issue. The author also opened an issue with the exact same text, see #35 |
Improve platform identification and fix Angular Universal crashes. Addresses (but does not close) #1
It looks like there is already existed solution for both (client and server side), for those who are using Angular Universal: https://www.npmjs.com/package/@ngx-utils/cookies |
Angular Universal SyntaxError: Unexpected token export |
Hi, use this import { AppModule } from './app.module';
import { CookieService } from 'ngx-cookie-service';
import { CookieServerService } from './cookie-server.service';
@NgModule({
imports: [
AppModule,
ServerModule,
ServerTransferStateModule,
ModuleMapLoaderModule,
FlexLayoutServerModule
],
providers: [
{
provide: CookieService,
useClass: CookieServerService
}
],
bootstrap: [AppComponent]
})
export class AppServerModule { } |
@bastienlemaitre |
ok, so we need a solution for the Document object, right? |
We solved that creating a class and inyecting the RESPONSE and REQUEST, but we passes that in server.ts... so we can use this.request.headers.cookie and this.response.cookie. So this solution probably is not valid for all people. in the server.ts where you render we passes that:
now in the cookie.server.ts we injected:
And now we can implement the methods.
|
hm, maybe there is a more simple solution? |
I hope! haha our problem was that we need to use the cookie from the request and the response... Don't know other solution know... That is our cookie-server.service.ts
I hope that can help you! If you need something more tell me :) Edit: Important Thing! this.response.cookie is encodeUri by default! hahaha i had problem with this xD |
What I got from here - https://angular.io/guide/universal |
Probably that is the solution, but i try to use DOCUMENT and i get this error Probably I don't used correctly hehe, i will try later to remplace my RESPONSE and REQUEST to DOCUMENT. And one more thing... i think is better option create a server service than replace the original service with Document. If you replace in the original service you need to use isPlatformBroswser (or server) in every place. Thanks for your Work @stevermeister ! :) |
Used @DavidCMeier 's solution! Men that was clean! Almost lost hope since universal said there won't be any plans for cookie on server side. Only had to modify some functions and it was good to go! :) |
I just realized that I'm not sure what is expected behavior for cookie service on server side. |
@stevermeister I think we should implement this. I do see many projects using SSR. I might be able to implement this. |
@pavankjadda we can think about own way, but are there any standard for server-side cookies? |
@stevermeister honestly I have no idea about standard. But I can tell you this. In one of my recent NextJS (React) projects, I used modified version of my library react-cookie-service. With simple changes I was able to get it working. I can try to do that same here, test it with sample projects. Perhaps we can people in this thread to test it. |
but I conceptually don't understand it. |
You don't have to. We still store them in browser but you just have to make sure |
@stevermeister I created sample repo that demonstrates this. Clone the project and run as per instructions in Readme.md file |
@pavankjadda I used your code and got "Cannot read property 'getHeader' of null" |
Hy guys,
great module! Are you planning to implement a way to use the module also on the server side.
So that the cookies are read from the intial request captured by node?
The text was updated successfully, but these errors were encountered: