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

[node-xmcloud-proxy] Update Netlify deployment guide in readme #2041

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Our versioning strategy is as follows:
* `[sitecore-jss-angular]` `CanActivate` and `CanResolve` now additionally accept `router` as a parameter ([#2029](https://github.com/Sitecore/jss/pull/2029))
* `[templates/angular]` Remove unnecessary PROXY_HOST setting ([#2036](https://github.com/Sitecore/jss/pull/2036)):
* The environment variable `PROXY_HOST` is no longer required and can be fully removed from the application.
* `[node-xmcloud-proxy]` Update Netlify deployment guide ([#2041](https://github.com/Sitecore/jss/pull/2041))

### 🛠 Breaking Change

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,64 +91,73 @@ If the operation is successful, you’ll see the following message:

Follow these steps to deploy your application to Netlify. The deployed site can be used as an editing host in XM Cloud.

1. Run `npm init` in the root directory (which contains SPA and Node XM Cloud Proxy app folder) and add the following scripts to package.json:
```
"build": "cd ./<your-proxy-app-name> && npm run build-all && cd ..",
"install": "cd ./<your-proxy-app-name> && npm install && npm run install-all && cd ..",
```
2. Ensure that `<your-proxy-app-name>/package.json` includes the following commands to handle the build and install steps properly:
```
"build-all": "cd ../angular && npm run build && cd ../<your-proxy-app-name> && tsc",
"install-all": "cd ../angular && npm i && cd ../<your-proxy-app-name>"
```
1. Run `npm init` in the root directory (which contains SPA and Node XM Cloud Proxy app folders) and add the following scripts to package.json:
```
"build": "cd ./<your-proxy-app-folder> && npm run build-all && cd ..",
"install": "cd ./<your-proxy-app-folder> && npm install && npm run install-all && cd .."
```
2. Ensure that `<your-proxy-app-folder>/package.json` includes the following commands to handle the build and install steps properly:
```
"build-all": "cd ../angular && npm run build && cd ../<your-proxy-app-folder> && tsc",
"install-all": "cd ../angular && npm i && cd ../<your-proxy-app-folder> && npm i"
```
3. Configure `serverless-http`:
- Install the npm package
```
npm i serverless-http
```
- Import serverless-http in `<your-proxy-app-name>/src/index.ts` file.
- Install the serverless-http package :
- in case you are deploying standalone angular + proxy run the following from the inside of `<your-proxy-app-folder>`:
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
```
npm i serverless-http
```
- in case you are in the context of [xmcloud-foundation-head](https://github.com/sitecorelabs/xmcloud-foundation-head), it has a pnpm monorepo setup, so if run the following from the inside of `<your-proxy-app-folder>`:
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
```
pnpm add serverless-http
```
- Import serverless-http in `<your-proxy-app-folder>/src/index.ts` file and export the serverless handler:
```
export const handler = serverless(server);
import serverless from 'serverless-http';
...
export const handler = serverless(server);
```
4. Create a `netlify.toml` file and ensure that the following Netlify configuration is added there:
- The following allows the proxy app to be treated as Netlify functions. [Functions Overview](https://docs.netlify.com/functions/overview/)
```
[functions]
directory = "<your-proxy-app-name>/src"
node_bundler = "esbuild"
included_files = ["<your-proxy-app-name>/dist/**"]
```
- To ensure that static assets are accessed properly, you might need to add the following redirects statement to the toml file:
```
[[redirects]]
from = "/dist/browser/*"
status = 200
to = "/browser/:splat"
```
- By default, redirects won’t be applied if there’s a file with the same path as the one defined in the `from` property. Setting `force` to `true` will make the redirect rule take precedence over any existing files.
```
[[redirects]]
from = "/*"
status = 200
to = "/.netlify/functions/index/:splat"
force = true
```
- Add the following build command:
```
[build]
command = "npm run build"
publish = "<your-proxy-app-name>/dist"
```
```
[functions]
directory = "<your-proxy-app-folder>/src"
node_bundler = "esbuild"
included_files = ["<your-proxy-app-folder>/dist/**"]
[[redirects]]
from = "/dist/browser/*"
status = 200
to = "/browser/:splat"
[[redirects]]
from = "/*"
status = 200
to = "/.netlify/functions/index/:splat"
force = true
[build]
command = "npm run build"
publish = "<your-proxy-app-folder>/dist"
```
- The `[functions]` section allows the proxy app to be treated as Netlify functions. [Functions Overview](https://docs.netlify.com/functions/overview/)
- The first `[[redirects]]` section is to ensure that static assets are accessed properly.
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
- The second `[[redirects]]` section: by default, redirects won’t be applied if there’s a file with the same path as the one defined in the `from` property. Setting `force` to `true` will make the redirect rule take precedence over any existing files, thus preventing files in the deploy folder to be publicly accessible.
yavorsk marked this conversation as resolved.
Show resolved Hide resolved

5. Create your [Netlify deployment](https://www.netlify.com/blog/2016/09/29/a-step-by-step-guide-deploying-on-netlify/):
- Set up all your necessary environment variables like `SITECORE_EDGE_CONTEXT_ID`, `SITECORE_SITE_NAME` etc.
- Make sure to configure Netlify to use latest LTS version of Node.js
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
- Configure your build settings in the Build and Deploy tab under Site configuration.
- sample configuration:
```
Base Directory: /
Build command: npm run build
Publish directory: /proxy/dist
Functions directory: /proxy/src
```
- sample configuration for standalone angular + proxy deployment:
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
```
Base Directory: /
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
Build command: npm run build
Publish directory: /proxy/dist
Functions directory: /proxy/src
```
- sample configuration in case you are in the context of [xmcloud-foundation-head](https://github.com/sitecorelabs/xmcloud-foundation-head):
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
```
Base Directory: /headapps/spa-starters/
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
Build command: npm run build
Publish directory: /headapps/spa-starters/proxy/dist
Functions directory: /headapps/spa-starters/proxy/src
```
NOTE: If `proxy/dist` folder is not picked up properly by Netlify make sure that the `PROXY_BUILD_PATH` env variable is unix style path e.g. `../proxy/dist`

### Deploy to Vercel
Expand Down