-
Notifications
You must be signed in to change notification settings - Fork 278
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
[Headless SSR Proxy] Fix shape of config object #979
Merged
illiakovalenko
merged 4 commits into
Sitecore:dev
from
sc-nikolaoslazaridis:bugfix/479510-Fix-shape-of-config-object
Apr 14, 2022
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
19261ae
Created a new interface LayoutServiceData in sitecore-jss-proxy/Proxy…
sc-nikolaoslazaridis c794950
Added information to README.md files in create-sitecore-jss/node-head…
sc-nikolaoslazaridis 53e1854
Made serverBundle optional property in ProxyConfig interface
sc-nikolaoslazaridis ac93381
Made serverBundle mandatory in ProxyConfig. Changed the config object…
sc-nikolaoslazaridis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ The setup is using `sitecore-jss-proxy` that enables request proxying to Sitecor | |
<!--- | ||
@TODO: Update to version 20.0.0 docs before release | ||
--> | ||
|
||
[Documentation](https://doc.sitecore.com/xp/en/developers/hd/190/sitecore-headless-development/server-side-render-jss-apps-headlessly-using-the-jss-proxy.html) | ||
|
||
> This is a sample setup that is not officially supported by Sitecore. | ||
|
@@ -45,6 +46,8 @@ The following environment variables can be set to configure the proxy instead of | |
| `SITECORE_PATH_REWRITE_EXCLUDE_ROUTES` | Optional. Pipe-separated list of absolute paths that should not be rendered through SSR. Defaults can be seen in [config.js](./config.js). | | ||
| `SITECORE_ENABLE_DEBUG` | Optional. Writes verbose request info to stdout for debugging. Defaults to `false`. | | ||
|
||
These environment variables can be set in the .env file located in the root of the app. | ||
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. Same here (put into statement above the table). |
||
|
||
## Build & run | ||
|
||
1. Run `npm install` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
import { Config as HttpProxyConfig } from 'http-proxy-middleware'; | ||
import { AppRenderer } from './AppRenderer'; | ||
import { RenderResponse } from './RenderResponse'; | ||
import { RouteUrlParser } from './RouteUrlParser'; | ||
|
||
/** A reply from the Sitecore Layout Service */ | ||
export interface LayoutServiceData { | ||
sitecore: { | ||
context: { | ||
[key: string]: unknown; | ||
language?: string; | ||
site?: { | ||
name?: string; | ||
}; | ||
}; | ||
}; | ||
} | ||
|
||
export interface ProxyConfig { | ||
/** Hostname to proxy to (i.e. Sitecore CD server 'http://siteco.re') */ | ||
|
@@ -30,7 +45,13 @@ export interface ProxyConfig { | |
onError?: ( | ||
error: Error, | ||
response: IncomingMessage | ||
) => Promise<{ statusCode?: number; content?: string }>; | ||
) => | ||
| null | ||
| { | ||
statusCode?: number; | ||
content?: string; | ||
} | ||
| Promise<{ statusCode?: number; content?: string }>; | ||
/** Enables transforming SSR'ed HTML after it is rendered, i.e. to replace paths. */ | ||
transformSSRContent?: ( | ||
response: RenderResponse, | ||
|
@@ -42,7 +63,7 @@ export interface ProxyConfig { | |
request: IncomingMessage, | ||
response: ServerResponse, | ||
proxyResponse: IncomingMessage, | ||
layoutServiceData: { [key: string]: unknown } | ||
layoutServiceData: LayoutServiceData | ||
) => // eslint-disable-next-line @typescript-eslint/ban-types | ||
Promise<object>; | ||
/** Hook to alter HTTP headers in a custom way. */ | ||
|
@@ -53,4 +74,10 @@ export interface ProxyConfig { | |
) => void; | ||
/** Responses from the proxy greater than this size (in bytes) are rejected. */ | ||
maxResponseSizeBytes?: number; | ||
/** The require'd server.bundle.js file from your pre-built JSS app */ | ||
serverBundle?: { | ||
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. Make it required, and fix unit tests |
||
[key: string]: unknown; | ||
renderView: AppRenderer; | ||
parseRouteUrl: RouteUrlParser; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's put this into the statement above the table (it might get lost down here). Something like:
"The following environment variables can be set to configure the proxy instead of modifying
config.js
. You can use the .env file located in the root of the app or set these directly in the environment (for example, in containers)."