-
-
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
feat(request): add request provider for SSR without adding express as… #206
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json", | ||
"dest": "../../../dist/ngx-cookie-service/express-ssr", | ||
"lib": { | ||
"entryFile": "src/public-api.ts" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "ngx-cookie-service/express-ssr", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"@nguniversal/express-engine": "^13.0.1", | ||
"express": "^4.17.2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {StaticProvider} from '@angular/core'; | ||
import {REQUEST} from '@nguniversal/express-engine/tokens'; | ||
import {REQUEST_PROVIDER_TOKEN, RequestProvider} from 'ngx-cookie-service/request-provider'; | ||
|
||
export const requestProviderFactory = (request: RequestProvider) => { | ||
return request; | ||
}; | ||
|
||
export const expressRequestProvider: StaticProvider = { | ||
provide: REQUEST_PROVIDER_TOKEN, | ||
useFactory: requestProviderFactory, | ||
deps: [REQUEST] | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './express-request.provider'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json", | ||
"dest": "../../../dist/ngx-cookie-service/express-ssr", | ||
"lib": { | ||
"entryFile": "src/public-api.ts" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "ngx-cookie-service/request-provider", | ||
"license": "MIT" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './request.provider'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
|
||
export interface RequestProvider { | ||
headers? : { | ||
cookie: string; | ||
} | ||
} | ||
|
||
export const REQUEST_PROVIDER_TOKEN = new InjectionToken<RequestProvider>('request provider token') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ | |
// not use `DOCUMENT` injection and therefore doesn't work well with AoT production builds. | ||
// Package: https://github.com/BCJTI/ng2-cookies | ||
|
||
import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; | ||
import { Inject, Injectable, Optional, PLATFORM_ID } from '@angular/core'; | ||
import { DOCUMENT, isPlatformBrowser } from '@angular/common'; | ||
import { REQUEST_PROVIDER_TOKEN, RequestProvider } from 'ngx-cookie-service/request-provider'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
|
@@ -14,7 +15,8 @@ export class CookieService { | |
constructor( | ||
@Inject(DOCUMENT) private document: Document, | ||
// Get the `PLATFORM_ID` so we can check if we're in a browser. | ||
@Inject(PLATFORM_ID) private platformId | ||
@Inject(PLATFORM_ID) private platformId: any, | ||
@Optional() @Inject(REQUEST_PROVIDER_TOKEN) private request: RequestProvider | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @valorkin I see you created @stevermeister take a look at this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, now playing with it here - https://github.com/stevermeister/ssr-coookie |
||
) { | ||
this.documentIsAccessible = isPlatformBrowser(this.platformId); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I have very little knowledge on this. I will read more about this